def getDynamicMeshMobmap(trajFileName, dynamicFileName, meshcode_level):
    Timestamps = getTimestamps(trajFileName)
    TIMENUMBER = len(Timestamps)
    TS = {}
    for i in range(TIMENUMBER):
        TS[Timestamps[i]] = i
    print('getDynamicMesh Started : ', time.ctime())
    R = []
    for i in range(TIMENUMBER):
        R.append({})
    with open(trajFileName, 'r') as rf:
        reader = csv.reader(rf)
        for line in reader:
            timestamp = line[1]
            lon = float(line[2])
            lat = float(line[3])
            meshcode = ju.to_meshcode(lat, lon, meshcode_level)
            if (meshcode in R[TS[timestamp]]):
                R[TS[timestamp]][meshcode] += 1
            else:
                R[TS[timestamp]][meshcode] = 1
    with open(dynamicFileName, 'w') as wf:
        wf.write('@dynamic-mesh\n')
        wf.write(('@use-mesh-code,' + str(meshcode_level)))
        for i in range(len(R)):
            timestamp = Timestamps[i]
            for key in R[i]:
                meshcode = key
                meshpop = R[i][meshcode]
                wf.write((','.join([timestamp, meshcode, str(meshpop)]) + '\n'))
    print('getDynamicMesh Ended : ', time.ctime())
def getDynamicMeshMobmap(trajFileName, dynamicFileName, meshcode_level):
    Timestamps = getTimestamps(trajFileName)
    TIMENUMBER = len(Timestamps)
    TS = {}
    for i in range(TIMENUMBER):
        TS[Timestamps[i]] = i
    print('getDynamicMesh Started : ', time.ctime())
    R = []
    for i in range(TIMENUMBER):
        R.append({})
    with open(trajFileName, 'r') as rf:
        reader = csv.reader(rf)
        for line in reader:
            timestamp = line[1]
            lon = float(line[2])
            lat = float(line[3])
            meshcode = ju.to_meshcode(lat, lon, meshcode_level)
            if (meshcode in R[TS[timestamp]]):
                R[TS[timestamp]][meshcode] += 1
            else:
                R[TS[timestamp]][meshcode] = 1
    with open(dynamicFileName, 'w') as wf:
        wf.write('@dynamic-mesh\n')
        wf.write(('@use-mesh-code,' + str(meshcode_level)))
        for i in range(len(R)):
            timestamp = Timestamps[i]
            for key in R[i]:
                meshcode = key
                meshpop = R[i][meshcode]
                wf.write((','.join([timestamp, meshcode, str(meshpop)]) + '\n'))
    print('getDynamicMesh Ended : ', time.ctime())