Comparing the results of an API call will be the same as comparing any other data in Solidity.
In your example, you are comparing weather, which is likely a uint256
. You will likely also need the date you are comparing, which would be a timestamp (also a uint256
). Each of these data sources would need a mapping of timestamp to temperature. The mappings would look as follows:
mapping (uint256 => uint256) public sourceOneWeather;
mapping (uint256 => uint256) public sourceTwoWeather;
mapping (uint256 => uint256) public sourceThreeWeather;
Comparing them would simply be to put them into a conditional statement and returning the output of whatever comparison you desire.
Add function example, per comments
An example comparison function would be:
function compareResults(uint256 _timestamp) public returns (uint256){
if (sourceOneWeather[_timestamp] > sourceTwoWeather[_timestamp]):
if (sourceOneWeather[_timestamp] > sourceThreeWeather[_timestamp]):
return sourceOneWeather[_timestamp];
else:
return sourceThreeWeather[_timestamp];
else if (sourceTwoWeather[_timestamp] > sourceThreeWeather[_timestamp]):
return sourceTwoWeather[_timestamp];
return sourceThreeWeather[_timestamp];