#!/usr/bin/perl use POSIX; use JSON::XS; #$DAY=18169; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(($DAY * 86400) + (12*60*60)); $humandate = sprintf("%d/%d/%04d", $mon+1, $mday, $year+1900); print "DATE($humandate)\n"; exit; $ARG_DATE_START = $ARGV[0]; $ARG_DATE_END = $ARGV[1]; $ARG_ETYPE = $ARGV[2]; $OUTFILE = $ARGV[3]; if ($ARG_DATE_START!~/\d\d\d\d\d\d\d\d/ || $ARG_DATE_END!~/\d\d\d\d\d\d\d\d/ || length($ARG_ETYPE) < 4 || length($OUTFILE) < 1) { print "USAGE: ./infer_run.pl STARTDATE ENDDATE ETYPE OUTFILE\n"; exit; } #load our query template... open(FILE, "./infer_query_day.json"); read(FILE, $json_template, (-s FILE)); close(FILE); $json_template=~s/\[TEMPLATE_ETYPE\]/$ARG_ETYPE/; $json_template=~s/\[TEMPLATE_TMPFILE\]/RESULTS.$$/; ######### #use this legacy SQL query to get the specific day of interest into the "TED" days-since-1970 format used by Infer... #SELECT (DATEDIFF(TIMESTAMP('2019-04-15'), TIMESTAMP('1970-01-01'))) #or just calculate directly... ($year, $mon, $day) = $ARG_DATE_START=~/(\d\d\d\d)(\d\d)(\d\d)/; $tedtime = mktime(0,0,12,$day,$mon-1,$year-1900); $TEDDAY_START = int($tedtime / 86400); print "STARTTED=$TEDDAY_START\n"; ($year, $mon, $day) = $ARG_DATE_END=~/(\d\d\d\d)(\d\d)(\d\d)/; $tedtime = mktime(0,0,12,$day,$mon-1,$year-1900); $TEDDAY_END = int($tedtime / 86400); print "ENDTED=$TEDDAY_END\n"; ######### ################## open(OUT, ">$OUTFILE"); #now iterate over each day... foreach $DAY ($TEDDAY_START...$TEDDAY_END) { print "Running ($DAY)\n"; $json_run = $json_template; $json_run=~s/\[TEMPLATE_DAY\]/$DAY/; $json_run=~s/\[TEMPLATE_ENDTIME\]/$end/; unlink("./RESULTS.$$"); system($json_run); ######## #and parse the results... $list = ''; $json_results = ''; open(FILE, "./RESULTS.$$"); read(FILE, $json_results, (-s FILE)); close(FILE); unlink("./RESULTS.$$"); $JSONREF = decode_json $json_results; foreach $entry (@{$JSONREF->{'results'}[0]->{'distributions'}[0]->{'entries'}}) { $val = $entry->{'value'}; $val=~s/^.*?=//; #$score = $entry->{'score'}; $matchgroup =$entry->{'matchedGroupCount'}; $totalgroup = $entry->{'totalGroupCount'}; $list .= "$val, "; } $list=~s/, $//; ######## #convert TED date to human format... ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(($DAY * 86400) + (12*60*60)); $humandate = sprintf("%d/%d/%04d", $mon+1, $mday, $year+1900); print OUT "$humandate\t$list\n"; print "\tRESULTS: $humandate\t($list)\n"; } close(OUT); ##################