Last active
March 8, 2022 01:58
-
-
Save Committing/6c6433539b896f4a8489c87ec0a0554b to your computer and use it in GitHub Desktop.
Ducky/Rich/Adem's homework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('memory_limit', -1); | |
set_time_limit(800); | |
include_once('functions.php'); | |
$fileName = "2018.csv"; | |
$resourceReader = fopen($fileName, 'r'); | |
$output = array(); | |
$return = array(); | |
$allowed_types = array( | |
'TMAX', | |
'TMIN' | |
); | |
$whitelisted_ids = array( | |
'UK000056225', | |
'UK000003377' | |
); | |
while (($row = fgetcsv($resourceReader)) !== FALSE) { | |
$id = $row[0]; | |
$date = $row[1]; | |
$type = $row[2]; | |
$value = $row[3]; | |
if (in_array($type, $allowed_types) && in_array($id, $whitelisted_ids)) { | |
$key = $id . $date; | |
$output[$key]['id'] = $id; | |
$output[$key]['date'] = $date; | |
$output[$key][$type] = $value; | |
if ( isset($output[$key]['TMAX']) && is_numeric($output[$key]['TMAX']) | |
&& isset($output[$key]['TMIN']) && is_numeric($output[$key]['TMIN'])) { | |
$return[$key] = $output[$key]['diff'] = $output[$key]['TMAX'] - $output[$key]['TMIN']; | |
} | |
} | |
} | |
pr($return); | |
die; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment