import json
import datetime
import createKmlFromSensorData

f = open("result.json", 'r', encoding='utf-8')
json_data = json.load(f)

index=0
startIndexOfLatestData=0
endIndexOfLatestData=0

#ŐṼf[^̎擾
for jsonRecord in json_data["values"]:
    #wb_sXLbv܂
    if(jsonRecord[0].split(' ')[0]=="t"):
        continue

    #̔r̂߁Ã݂f[^dateTime^ɕϊĕێ܂BtƎԂ̐lɂȂ܂B
    currentDataTime=datetime.datetime(\
      int(jsonRecord[0].split('/')[0]),\
      int(jsonRecord[0].split('/')[1]),\
      int(jsonRecord[0].split('/')[2]),\
      int(jsonRecord[1].split(':')[0]),\
      int(jsonRecord[1].split(':')[1]),\
      int(jsonRecord[1].split(':')[2]))

    if(index>0):
        #݂̃f[^Õf[^̎ԂłΌݎXVAf[^R[hԍL^܂
        if(currentDataTime>latestDateTime):
            latestDateTime = currentDataTime
            startIndexOfLatestData=index
    else:
        #͌ݎXV܂B
        latestDateTime = currentDataTime

    index=index+1
    endIndexOfLatestData=index

#f[^ƑΏۍs킽Akmlt@C쐬܂
createKmlFromSensorData.createKmlFromSensorData(json_data,startIndexOfLatestData+1,endIndexOfLatestData+1)
