示例#1
0
class PlotlyAPI(object):
    
    def __init__(self):
        self.influx = InfluxDB()
    
    def _create_scatter(self,expression,mode):
        try:
            axis_separate = expression.index(':')
            axis_label = expression[:axis_separate]
            expression = expression[axis_separate+1:]
        except:
            axis_label = 'y1'
            
        try:
            name_separate = expression.index(';')
            legend = expression[name_separate+1:]
        except:
            name_separate = len(expression)
            legend = expression
        result = self.influx.interpret(expression[:name_separate])
        x = result.index.to_pydatetime()
        y = result['value'].get_values()
        return Scatter(x=x,y=y,mode=mode,name=legend)
    
    def _create_ts(self,exp_list,title,mode='lines'):
        scatters = []
        for exp in exp_list:
            scatters.append(self._create_scatter(exp,mode))
        data = Data(scatters)
        py.plot(data, filename=title)
示例#2
0
文件: USData.py 项目: haomen/PlayData
'''
Created on Jul 18, 2015

@author: shaunz
'''
from QueryData.InfluxQuery import InfluxDB
from influxdb.influxdb08 import DataFrameClient
from pandas import DataFrame
import timeit

influx_Fred = InfluxDB()

interest_list = [
                 [ 'cpi_us_yoy', '(cpi_us/lag(cpi_us,12)-1)*100' ],
                 [ 'cpi_us_food_away_home_yoy', '(cpi_us_food_away_home/lag(cpi_us_food_away_home,12)-1)*100' ],
                 [ 'cpi_us_food_at_home_yoy', '(cpi_us_food_at_home/lag(cpi_us_food_at_home,12)-1)*100' ],
                 [ 'cpi_us_household_fuel_yoy', '(cpi_us_household_fuel/lag(cpi_us_household_fuel,12)-1)*100' ],
                 [ 'cpi_us_motor_fuel_yoy', '(cpi_us_motor_fuel/lag(cpi_us_motor_fuel,12)-1)*100' ],
                 [ 'cpi_us_owners_equiv_yoy', '(cpi_us_owners_equivalent/lag(cpi_us_owners_equivalent,12)-1)*100' ],
                 [ 'cpi_us_rent_yoy', '(cpi_us_rent/lag(cpi_us_rent,12)-1)*100' ],
                 [ 'cpi_us_household_fuel_yoy', '(cpi_us_household_fuel/lag(cpi_us_household_fuel,12)-1)*100' ],
                 [ 'cpi_us_medical_service_yoy', '(cpi_us_medical_service/lag(cpi_us_medical_service,12)-1)*100' ],
                 [ 'cpi_us_medical_commod_yoy', '(cpi_us_medical_commod/lag(cpi_us_medical_commod,12)-1)*100' ],
                 [ 'cpi_us_apparel_yoy', '(cpi_us_apparel/lag(cpi_us_apparel,12)-1)*100' ],
                 [ 'cpi_us_motor_yoy', '(cpi_us_motor/lag(cpi_us_motor,12)-1)*100' ],
                 [ 'cpi_us_education_yoy', '(cpi_us_education/lag(cpi_us_education,12)-1)*100' ],
                 [ 'cpi_us_communication_yoy', '(cpi_us_communication/lag(cpi_us_communication,12)-1)*100' ],
                 
                 [ 'wage_us_yoy', '(wage_us_weekly_nonsupervisory/lag(wage_us_weekly_nonsupervisory,12)-1)*100' ],
                 [ 'wti_yoy', '(avg(wti_spot,M)/lag(avg(wti_spot,M),12)-1)*100' ],
                 [ 'zillow_median_sale_price_yoy', '(zillow_median_sale_price/lag(zillow_median_sale_price,12)-1)*100' ],
示例#3
0
 def __init__(self):
     self.influx = InfluxDB()
示例#4
0
'''
Created on Jul 26, 2015

@author: shaunz
'''
from QueryData.InfluxQuery import InfluxDB
from pandas.core.config import option_context


influx = InfluxDB()
one = influx.query('cn_gdp_cum')
two = influx.interpret('anticum(cn_gdp_cum,Q)*100')

with option_context('display.max_rows', 9999, 'display.max_columns', 3):
        print one
        print two
'''
new_series = {}
for each in one.iterrows():
    if each[0].month != 1:
        prev_date = each[0] + DateOffset(months=-1)
        prev_date = prev_date.to_period('M').to_timestamp('M')
        monthly = each[1]['value']-one.loc[prev_date]
        new_series[each[0]] = monthly['value']
    else:
        new_series[each[0]] = each[1]['value']
     
Series(new_series)
''' 
示例#5
0
'''
Created on Jul 18, 2015

@author: shaunz
'''
from QueryData.InfluxQuery import InfluxDB
from pandas.stats.moments import rolling_corr
from pandas.tools.merge import concat
from pandas.core.common import isnull
from pandas.core.config import option_context

db = InfluxDB(db_name='Econ')
series_1 = db.interpret('cpi_us_owners_equiv_yoy')
series_2 = db.interpret('avg(zillow_median_sale_price_yoy,M)')
series_1.rename(columns={'value':'value_1'}, inplace=True)
series_2.rename(columns={'value':'value_2'}, inplace=True)
periods = 60
analysis_type = 'snapshot'

if(analysis_type=='snapshot'):
    for i in range(-36, 37): # go back i periods
        shifted_1 = series_1.shift(i)
        combined = concat([shifted_1['value_1'],series_2['value_2']],axis=1,join='outer')
        combined = combined.loc[isnull(combined['value_1']) != True]
        combined = combined.loc[isnull(combined['value_2']) != True]
        results = rolling_corr(combined['value_1'],combined['value_2'],window=periods)
        print '%d,%.4f' % (i, results[-1:].values)
elif(analysis_type=='history'):
    shifted_1 = series_1.shift(0)
    combined = concat([shifted_1['value_1'],series_2['value_2']],axis=1,join='outer')
    combined = combined.loc[isnull(combined['value_1']) != True]