#!/usr/bin/perl use POSIX; use JSON::XS; $ARG_DATE = $ARGV[0]; if ($ARG_DATE!~/\d\d\d\d\d\d\d\d/) { print "USAGE: ./infer_run.pl DATE ETYPE\n"; exit; } $ARG_ETYPE = $ARGV[1]; #load our query template... open(FILE, "./infer_query_15min.json"); read(FILE, $json_template, (-s FILE)); close(FILE); $json_template=~s/\[TEMPLATE_ETYPE\]/$ARG_ETYPE/; ######### #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=~/(\d\d\d\d)(\d\d)(\d\d)/; $tedtime = mktime(0,0,12,$day,$mon-1,$year-1900); $TEDDAY = int($tedtime / 86400); print "TED=$TEDDAY\n"; #interpolate into our template since this doesn't change for a given day... $json_template=~s/\[TEMPLATE_DAY\]/$TEDDAY/; $TIMEBASE = "${year}-${mon}-${day}T"; $TIMEBASEHUMAN = sprintf("%d/%d/%04d", $mon, $day, $year) . ' '; ######### ################## $OUTFILE = $ARG_ETYPE; $OUTFILE=~s/^Entity//; open(OUT, ">./$ARG_DATE.$OUTFILE.TXT"); #now iterate over the given day in 15 minute increments... foreach $hour (0...23) { foreach $min (0,15,30,45) { $start = sprintf("%02d:%02d:00", $hour, $min); $start = $TIMEBASE . $start . '+00:00'; $end = sprintf("%02d:%02d:59", $hour, $min + 14); $end = $TIMEBASE . $end . '+00:00'; #print "Running ($start -> $end)\n"; $json_run = $json_template; $json_run=~s/\[TEMPLATE_STARTTIME\]/$start/; $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); $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/, $//; ######## $humantime = $TIMEBASEHUMAN . sprintf("%d:%02d", $hour, $min); print OUT "$humantime\t$list\n"; print "\tRESULTS: $humantime\t($list)\n"; #if ($k++ > 5) { exit; } } } close(OUT); ##################