コード例 #1
0
ファイル: main.py プロジェクト: clarissebret/Sensing-and-IoT
def inject_user():
    user = User()
    name = "Kenza"
    query = user.get_user(name)
    dic = json.dumps(query, ensure_ascii=False)
    loaded_dic = json.loads(dic)
    return dict(mydict=loaded_dic)
コード例 #2
0
ファイル: recommender.py プロジェクト: jkeech/csce470
class Recommender:

    def __init__(self):
        self.user = User()
        self.ranker = Ranker()
	
    def build_states(self, states = None):
        """
            Add the states to the ranker in the proper format
        """
        if states is not None:
            self.ranker.states = states
        else:
            import os
            path = os.path.abspath(os.path.dirname(__file__))
            json_data = open(os.path.join(path,'crawler/results/state.json'))
            data = json.load(json_data)
            json_data.close()
            
            dict = data[1]
            for state in dict.iterkeys():
                state_vect = []
                for i in range(1, len(dict[state])):
                    state_vect.append(dict[state][i] / float(dict[state][0]))
                dict[state] = state_vect
            self.ranker.states = dict

    def build_counties(self, counties = None):
        """
            Add the counties to the ranker in the proper format
        """
        if counties is not None:
            self.ranker.counties = counties
        else:
            import os
            path = os.path.abspath(os.path.dirname(__file__))
            json_data = open(os.path.join(path,'crawler/results/county.json'))
            data = json.load(json_data)
            json_data.close()
            
            dict = data[1]
            for county in dict.iterkeys():
                county_vect = []
                for i in range(1, len(dict[county])):
                    county_vect.append(dict[county][i] / float(dict[county][0]))
                dict[county] = county_vect
            self.ranker.counties = dict

    def set_user(self, user):
        self.user = user

    def recommend_states(self):
        return self.ranker.rank_states(self.user.get_vector())

    def recommend_counties(self):
        return self.ranker.rank_counties(self.user.get_vector())
コード例 #3
0
def best_day(name, forecast_date):

    user = User()

    data = user.get_user(name)
    df = pd.DataFrame.from_dict(data, orient='columns')
    # df = (df - df.mean()) / df.std()
    # summary = df.describe()
    # summary.to_csv('summary.csv', sep=',')

    train = df[:int(float(5/7) * (len(df)))]
    valid = df[int(float(5/7) * (len(df))):]

    train.index = pd.DatetimeIndex(train.index.values, freq='1H')

    # Fit model on train set
    model = ARIMA(endog=train['activity'], order=(1,0,0), exog = train.iloc[:, 0:6])
    model_fit = model.fit(disp=0)
    print(model_fit.summary())

    #Forecast on valid set
    # prediction = model_fit.forecast(steps=len(valid), exog=valid.iloc[:,0:6])
    # print(prediction)

    # Fit model on entire set
    # model = ARIMA(endog=df['activity'], order=(1,0,0), exog=df.iloc[:, 0:6])
    # model_fit = model.fit(disp=0)

    resort_predictions = []
    time_predictions = []

    # Store exogenous variables from today's weather in exog dataframe
    for resort, q in resorts.items():
        current_weather = user.weather_query('today',q)
        index = dic_float(current_weather[0])[2]
        exog = pd.DataFrame(index=index[9:18], columns=list(df)[0:6])

        for j in range(0,len(list(df)[0:5])):
            values = dic_float(current_weather[j])[1]
            for i in range(0,9):
                exog.iloc[i][j] = values[i+9]

        exog['status'] = 1

        # Forecast for 24 hours
        prediction = model_fit.forecast(steps=9, exog=exog)

        # Total activity for the day
        prediction_second = 0
        for p in prediction[0]:
            prediction_second += p

        resort_predictions.append(resort)
        time_predictions.append(prediction_second)

    best_prediction_s = max(time_predictions)
    index = time_predictions.index(best_prediction_s)
    best_resort = resort_predictions[index]
    best_prediction = str(datetime.timedelta(seconds=best_prediction_s))

    print('%s will be perfect for you today! (time activity estimation: %s)' % (best_resort, best_prediction))
    return best_resort
コード例 #4
0
ファイル: recommender.py プロジェクト: jkeech/csce470
 def __init__(self):
     self.user = User()
     self.ranker = Ranker()