Commit 66bb71c2 by Tianyang

### add compare month

parent ec24abd2
No preview for this file type
 import numpy as np import matplotlib.pyplot as plt from functools import reduce from database_pre3 import connection import matplotlib.pyplot as plt import re import folium import random import datetime table_variable = [ 'date', 'lon', 'lat', 'station', 'time', 'alti', 'drct', 'dwpf', 'feel', 'gust', 'ice_accretion_1hr', 'ice_accretion_3hr', 'ice_accretion_6hr', 'metar', 'mslp', 'p01i', 'peak_wind_drct', 'peak_wind_gust', 'peak_wind_time', 'relh', 'sknt', 'skyc1', 'skyc2', 'skyc3', 'skyc4', 'skyl1', 'skyl2', 'skyl3', 'skyl4', 'tmpf', 'vsby', 'wxcodes'] def add (x,y): return x+y def abs_diff(x,y): longth = len(x) result = [] for i in range(longth): result.append(abs(x[i]-y[i])) total = 0 for each in result: total += each return total def diff(x,y): return x-y #caculate mean reduce #input [count,mean] def reduceFonction (x,y): result = [] for i in range(2): result.append(reduce(add,[x[i],y[i]])) return result #input [valeur] -> [count,mean] def mapFonction1 (x): return [1,x] #input [count,mean] -> [mean] def mapFonction2 (x): return x[1]/x[0] #Map reduce to caculate the means of each month of each station def mapReduce_kmeans(targetNB,start,end): results = dict() for row in session.execute("select * from caitiany.database_kmeans where date >= '%s' and date <= '%s' ALLOW FILTERING"%(start,end)): data_target = row[targetNB] if data_target == None: continue #We want to take out the month correspondant and add month into keys dateparser = re.compile("(\d+)-(?P\d+)-(\d+) (?P
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment