Prospectors_Market_Report

In [55]:
#this clears all variables
#%reset
In [56]:
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:90% !important; }</style>"))
In [57]:
import pandas as pd

from selenium import webdriver
from selenium.webdriver.common.by import By

import os
import bokeh

import numpy as np
import time
import datetime
from time import gmtime, strftime
import ast
import nbconvert
import nbformat
#from matplotlib.ticker import ScalarFormatter, FormatStrFormatter


from bokeh.plotting import figure, show, output_file,ColumnDataSource, save,  output_notebook
from bokeh.models import WheelZoomTool
from bokeh.models import PanTool
from bokeh.models import ResetTool
from bokeh.models import SaveTool
from bokeh.models import BoxZoomTool
from bokeh.models import CrosshairTool
from bokeh.models import HoverTool
#from bokeh.io import output_notebook
#output_notebook()

from bokeh.core.properties import value
from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.transform import dodge
from bokeh import plotting
from bokeh.models import HoverTool, PanTool, ResetTool, WheelZoomTool

import warnings
warnings.filterwarnings('ignore')

# this sets up notebook export to .html
import IPython.core.display as di

# This line will hide code by default when the notebook is exported as HTML
di.display_html('<script>jQuery(function() {if (jQuery("body.notebook_app").length == 0)' + 
                '{ jQuery(".input_area").toggle(); jQuery(".prompt").toggle();}});</script>', raw=True)

# This line will add a button to toggle visibility of code blocks, for use with the HTML export version
#di.display_html('''<button onclick="jQuery('.input_area').toggle(); jQuery('.prompt').toggle();">Toggle code</button>''', raw=True)
In [58]:
print('If you like this site and find it helpful. Feel free to send a tip to snowandsurf2. Thanks! ')
print('\n')
print('If you are having trouble viewing the charts, try Chrome Browser and clear your cache.')
print('\n')
print('last updated: ' +  strftime("%Y-%m-%d %H:%M:%S", gmtime()) + ' GMT')
If you like this site and find it helpful. Feel free to send a tip to snowandsurf2. Thanks! 


If you are having trouble viewing the charts, try Chrome Browser and clear your cache.


last updated: 2020-02-23 04:36:14 GMT
In [59]:
item_dict = {2:'wood',
             3:'stone', 
             4:'coal', 
             5:'clay', 
             6:'ore', 
             7:'stoneblock', 
             8:'stoneplate', 
             9:'beam', 
             10:'board', 
             11:'woodgirder', 
             12:'brick', 
             13:'tile', 
             14:'steelblock', 
             15:'steelplate', 
             16:'nail', 
             17:'shovel',
             18:'spade',
             19:'pickaxe',
             20:'hammer',
             21:'sledge',
             22:'axe',
             23:'saw',
             24:'goldpan', 
             25:'cartbody', 
             26:'cartbody', 
             27:'cartwheel',
             28:'wagon',
             29:'wagonbody',
             30:'wagonwheel',
             31:'coffee bean'}
In [60]:
def scrape_bloks(driver_loc, url):
    driver = webdriver.Chrome(driver_loc) 
    #browser = webdriver.Chrome()
    driver.get(url)
    
    
    account_page_list = []
    market_tab_list = []
    
    time.sleep(45)
    
    contract_button = driver.find_element_by_xpath('//*[@id="top-container"]/div[2]/div[2]')
    contract_button.click()
    

    
    market_tab_button = driver.find_element_by_xpath('//*[@id="mobile-buttons"]/div[1]/span[5]')
    market_tab_button.click()
    
    limit_form = driver.find_element_by_xpath('//*[@id="mobile-buttons"]/div[2]/div/div[4]/input')
    limit_form.send_keys(str(99999) + "\n")
    refresh_button = driver.find_element_by_xpath('//*[@id="mobile-buttons"]/div[2]/div/div[5]/div')
    refresh_button.click()
    
    time.sleep(45)
    
    market_tab = driver.find_element_by_xpath('//*[@id="info"]/tbody')
    
    time.sleep(45)
    account_page = driver.find_element_by_xpath('//*[@id="info"]/tbody')
    
   

    for c in (market_tab.text).splitlines():
        market_tab_list.append(c)

    #print(market_tab_list)
    
    return driver, account_page_list, market_tab_list
In [61]:
driver = r'C:\chromedriver_win32\chromedriver.exe'
url = 'https://bloks.io/account/prospectorsc'
driver, account_page_list, market_tab_list = scrape_bloks(driver, url)
In [62]:
##strftime("%Y%m%d_%H%M%S", gmtime())
#market_tab_list
In [63]:
df_list = []
count = 0
for i in market_tab_list:

    middle_elems = market_tab_list[count][market_tab_list[count].index("{"):market_tab_list[count].index("}")+1]
    
    middle_elems_dict =  ast.literal_eval(middle_elems)
    
    middle_elems_dict['type_id'] = item_dict[middle_elems_dict['type_id']]


    left_side_elems = market_tab_list[count][:market_tab_list[count].index("{")]

    left_side_elems = left_side_elems.rstrip()

    left_side_elems = left_side_elems.split()

    middle_elems_dict['id'] = int(left_side_elems[1])
    middle_elems_dict['loc_id'] = int(left_side_elems[2])
    middle_elems_dict['owner'] = (left_side_elems[3])

    right_side_elems = market_tab_list[count][market_tab_list[count].index("}")+2:]
    right_side_elems = right_side_elems.split()
    middle_elems_dict['price'] = int(right_side_elems[0])

    df = pd.DataFrame(middle_elems_dict, index=[count])
    df_list.append(df)
    count+=1
In [64]:
catted_df = pd.concat(df_list)
In [65]:
for k, v in item_dict.items():
    
    item_df = catted_df[catted_df['type_id'] == v]

    #print(item_df)
In [66]:
#pd.set_option('display.max_rows', 1000)
#catted_df.sort_values('type_id').reset_index()
#catted_df_gb = catted_df.drop('loc_id', axis=1)
#catted_df_gb.groupby('type_id').describe().round(1)
In [67]:
cdf_1 = catted_df[['type_id', 'price']]
cdf_1.groupby('type_id').describe().sort_values(('price', '50%'), ascending=False).round(1)
Out[67]:
price
count mean std min 25% 50% 75% max
type_id
wagon 13.0 16746.5 8153.5 4220.0 14000.0 15000.0 16000.0 39999.0
sledge 17.0 10336.0 12745.7 3500.0 6500.0 6850.0 7999.0 59000.0
coffee bean 22.0 8791.0 4564.8 4775.0 5462.5 6249.5 13249.2 20000.0
pickaxe 29.0 5740.4 4791.5 2750.0 4349.0 4500.0 5000.0 29000.0
cartbody 5.0 5237.6 2069.1 4000.0 4000.0 4500.0 4800.0 8888.0
goldpan 43.0 3381.9 1494.8 1000.0 2912.5 3000.0 3249.5 9988.0
shovel 26.0 2887.8 5364.5 700.0 1700.0 1758.5 1887.5 29000.0
spade 21.0 1753.9 745.5 900.0 1350.0 1699.0 1900.0 4588.0
woodgirder 12.0 1487.4 148.0 1249.0 1462.5 1500.0 1525.0 1750.0
hammer 16.0 3309.0 6879.4 800.0 1199.8 1425.0 2000.0 29000.0
axe 17.0 1411.4 914.3 35.0 1000.0 1350.0 1600.0 4088.0
brick 4.0 1183.0 307.9 900.0 970.5 1122.0 1334.5 1588.0
saw 24.0 2363.4 5730.9 250.0 790.0 999.5 1500.0 29000.0
tile 10.0 1066.3 298.4 734.0 861.8 900.0 1237.5 1588.0
steelplate 11.0 838.9 575.3 535.0 547.5 603.0 647.0 2000.0
steelblock 13.0 759.4 436.1 535.0 585.0 600.0 625.0 2000.0
board 15.0 584.7 151.0 424.0 466.5 548.0 625.0 1000.0
stoneblock 11.0 1486.5 2843.8 292.0 348.0 500.0 997.5 9999.0
beam 15.0 276.5 63.6 200.0 230.0 260.0 310.0 400.0
coal 28.0 217.9 72.0 150.0 177.5 189.5 232.8 450.0
clay 29.0 198.5 102.4 130.0 160.0 178.0 193.0 700.0
stoneplate 11.0 149.4 84.5 45.0 69.5 155.0 187.0 290.0
ore 30.0 78.7 22.2 40.0 65.0 72.5 89.8 150.0
wood 25.0 74.1 18.2 60.0 62.0 68.0 80.0 140.0
stone 27.0 3427.1 17681.5 4.0 8.5 16.0 36.0 91900.0
nail 14.0 8.1 3.3 6.0 6.0 7.0 8.0 16.0
In [68]:
#strftime("%Y/%m/%d %H:%M:%S")
catted_df['date'] = strftime("%Y/%m/%d %H:%M:%S")
#catted_df
In [69]:
strftime("%Y-%m-%d %H:%M:%S")

catted_df.to_csv(os.path.join(r'C:\Users\matth\bokeh_snow_tracker\market_reports', 'market_report_' + strftime("%Y%m%d_%H%M%S") + '.csv'))
In [70]:
def do_bokeh_bar_chart(df, item):

    df_slice = df[df['type_id'] == item]

    df_slice['account'] = df_slice.index

    delivery_stat_cols = ['price', 'amount']
    colors = ['darkseagreen', 'lightcoral']

    account = df_slice.owner.to_list()

    from collections import Counter

    account = [s + '_' + str(suffix) if num>1 else s for s,num in Counter(account).items() for suffix in range(1, num+1)]

    price = df_slice.price.to_list()
    amount = df_slice.amount.to_list()

    source = ColumnDataSource(data=dict(account=account, price=price, amount=amount))

    hover_price = HoverTool( mode='vline', line_policy='nearest', names=['price'],
    tooltips=[("price", "@{price}{0.0[0]}")],point_policy="follow_mouse")

    hover_amount = HoverTool( mode='vline', line_policy='nearest', names=['amount'],
    tooltips=[("amount", "@{amount}{0.0[0]}")],point_policy="follow_mouse")

    strftime("%Y-%m-%d %H:%M:%S", gmtime())
    
    title= item + ', last updated ' +  strftime("%Y-%m-%d %H:%M:%S", gmtime()) + ' GMT' 

    v = figure(x_range=account, y_range = [10 ** 0, 10 ** 7], 
               plot_height=500, 
               plot_width=900, 
               title=title,
               toolbar_location='right',
               tools=['pan', 'box_zoom', 'wheel_zoom', 'save','reset', hover_price, hover_amount],
               y_axis_type="log" )

    v.vbar(x=dodge('account', -0.1, range=v.x_range), 
           top='price', 
           width=0.2, 
           source=source, 
           bottom=0.01, 
           name='price', 
           color='orange',
           legend=value('price'))
    v.vbar(x=dodge('account', +0.1, range=v.x_range), 
           top='amount', 
           width=0.2, 
           source=source, 
           bottom=0.01, 
           name='amount',
           legend=value('amount'))
    from bokeh.models import NumeralTickFormatter
    v.yaxis[0].formatter = NumeralTickFormatter(format="0.0")

    v.xgrid.grid_line_color = None
    v.legend.orientation = "horizontal"
    v.legend.location = "top_left"
    import math
    v.xaxis.major_label_orientation = math.pi/2.5


    show(v)

    
In [71]:
type_id_list = catted_df['type_id'].unique().tolist()
In [72]:
csvs = os.listdir(r'C:\Users\matth\bokeh_snow_tracker\market_reports')
In [73]:
csv_dfs_list = []
In [74]:
for csv in csvs:
    csv = os.path.join(r'C:\Users\matth\bokeh_snow_tracker\market_reports', csv )

    df_a = pd.read_csv(csv)
    df_a['date'] = pd.to_datetime(df_a.date, dayfirst=False, yearfirst=True)+ pd.Timedelta('7 hours')
    #df_a.set_index('date', inplace=True)
    df_a = df_a[df_a['price'] < 10000000]
    df_b = df_a.groupby(['type_id']).agg(['median'])    
    #df_b = df_a.groupby(['type_id']).agg(['min']) 
    
    df_b['date'] = df_a['date'].max()
    csv_dfs_list.append(df_b)
In [75]:
master_csvs_df = pd.concat(csv_dfs_list)
master_csvs_df['item'] = master_csvs_df.index
#master_csvs_df.set_index('date', inplace=True)
In [76]:
#master_csvs_df = master_csvs_df[master_csvs_df['item'] == 'axe']
#master_csvs_df.columns
In [77]:
master_csvs_df.to_csv('master_df_example.csv')


#
#master_csvs_df
In [78]:
#master_csvs_df
In [79]:
    
    
raw_materials_list = ['clay', 'coal', 'ore', 'stone', 'wood', 'coffee bean']

refined_materials_list = ['board', 'beam', 'board', 'brick', 'nail', 'steelblock', 'steelplate', 'stoneblock', 'stoneplate', 'tile', 'woodgirder']

tools_list = ['axe', 'goldpan', 'hammer', 'pickaxe', 'saw', 'shovel', 'sledge', 'spade']

transport_list = ['cartbody', 'wagon']

task_list = raw_materials_list + refined_materials_list + tools_list + transport_list
In [ ]:

In [80]:
def create_bokeh_item_time_series(df, task_list, color_list, title):
    
    def datetime_formatter(x):
        return  np.array(x, dtype=np.datetime64)

    if task_list == raw_materials_list:
        fig_y_range = (0, 2000)
    elif task_list == refined_materials_list:
        fig_y_range = (0, 2000)
    elif task_list == tools_list:
        fig_y_range = (0, 25000)
    elif task_list == transport_list:
        fig_y_range = (0, 100000)
    
    from bokeh.palettes import Spectral11
    p_mpw = figure(y_range = fig_y_range,
                   plot_width = 800, 
                   plot_height = 400,
                   sizing_mode = 'scale_width', 
                x_axis_type="datetime", 
                toolbar_location='right', 
                title= title, 
                active_drag="pan", 
                tools="reset,wheel_zoom,box_zoom,save,pan", 
                  #y_axis_type="log",  
        output_backend="webgl")

    for task, color in zip(task_list, color_list):
    
        df_2 = df[df['item'] == task]
        
        
            
        #print(df_2)
    
        source = ColumnDataSource(data={'date' : datetime_formatter(df_2['date']),
                                                    'price' : df_2['price']['median'], 
                                       'item': df_2['item']})

        
        p_mpw.line(x='date', y='price', line_width=3, line_dash='solid', color=color, source=source,legend=task )
     
        
        
        p_mpw.add_tools(HoverTool(tooltips=[('item','@item'),('date','@date{%c}'), ( 'price',  '@{price}{0.0[0]}' ), ],
            formatters={'date':'datetime', 'price':'numeral', 'item':'printf'}, toggleable=False))
    

    p_mpw.legend.location =  'center_left'
    p_mpw.legend.label_text_font_size = '7pt'
    p_mpw.legend.spacing = 0
    p_mpw.legend.label_height = 2
    p_mpw.legend.click_policy="hide"

    p_mpw.title.text_font_size = '15pt'
    p_mpw.title.align = "center"
    
    
    p_mpw.yaxis.axis_label="Price"
    p_mpw.yaxis.axis_label_text_font_size = "15pt"
    p_mpw.yaxis.major_label_text_font_size = "15pt"
    p_mpw.yaxis.axis_label_text_font = "times"
    p_mpw.yaxis.axis_label_text_color = "black"

    
    p_mpw.xaxis.axis_label="Date"
    p_mpw.xaxis.axis_label_text_font_size = "15pt"
    p_mpw.xaxis.major_label_text_font_size = "15pt"
    p_mpw.xaxis.axis_label_text_font = "times"
    p_mpw.xaxis.axis_label_text_color = "black"
    
    from bokeh.models import NumeralTickFormatter
    p_mpw.yaxis[0].formatter = NumeralTickFormatter(format="0.0")
    #p_mpw.xaxis[0].formatter = NumeralTickFormatter(format="0.0")
    
    #output_file("INTERACTIVE_DUKE_TRACKER_MIDWEST_MILES_PER_WEEK_" + current_time + ".html")
    p_mpw.min_border = 3
    cwd = os.getcwd()
    

    #global bokeh_mpw_html
    
    
    #bokeh_mpw_html =  os.path.join(cwd , "INTERACTIVE_DUKE_TRACKER_MIDWEST_MILES_PER_WEEK_" + current_time + ".html")
    
    #save(p_mpw)
    
    output_notebook()
    

               
    show(p_mpw)
    
    
'''   
from bokeh.palettes import Category20              
#color_list = Category20[20] + Category20[20] 
color_list = list(task_color_dic.values())
dash_list = list(dash_dic.values())
create_bokeh_item_time_series(master_csvs_df, task_list, color_list, title)
''' ;
In [ ]:
 
In [81]:
task_list = raw_materials_list + refined_materials_list + tools_list + transport_list
In [82]:
from bokeh.palettes import Category20              
color_list = Category20[20] + Category20[20] 
title = 'Resources Median Price'

resources_bokeh = create_bokeh_item_time_series(master_csvs_df, raw_materials_list, color_list, title)
Loading BokehJS ...
In [ ]:
 
In [ ]:

In [ ]:
 
In [83]:
        
#color_list = Category20[20] + Category20[20] 
title = 'Materials Median Price'
create_bokeh_item_time_series(master_csvs_df, refined_materials_list, color_list, title)
Loading BokehJS ...
In [84]:
             
color_list = Category20[20] + Category20[20] 
title = 'Tools Median Price'
create_bokeh_item_time_series(master_csvs_df, tools_list, color_list, title)
Loading BokehJS ...
In [85]:
             
color_list = Category20[20] + Category20[20] 
title = 'Transport Median Price'
create_bokeh_item_time_series(master_csvs_df, transport_list, color_list, title)
Loading BokehJS ...
In [ ]:
 
In [ ]:
 
In [ ]:
        
In [ ]:
 
In [ ]:
 

wax

In [86]:
driver = r'C:\chromedriver_win32\chromedriver.exe'
url = 'https://wax.bloks.io/account/prospectorsc'
driver, account_page_list, market_tab_list = scrape_bloks(driver, url)
In [87]:
#market_tab_list
In [88]:
df_list = []
count = 0
for i in market_tab_list:

    middle_elems = market_tab_list[count][market_tab_list[count].index("{"):market_tab_list[count].index("}")+1]
    
    middle_elems_dict =  ast.literal_eval(middle_elems)
    
    middle_elems_dict['type_id'] = item_dict[middle_elems_dict['type_id']]


    left_side_elems = market_tab_list[count][:market_tab_list[count].index("{")]

    left_side_elems = left_side_elems.rstrip()

    left_side_elems = left_side_elems.split()

    middle_elems_dict['id'] = int(left_side_elems[1])
    middle_elems_dict['loc_id'] = int(left_side_elems[2])
    middle_elems_dict['owner'] = (left_side_elems[3])

    right_side_elems = market_tab_list[count][market_tab_list[count].index("}")+2:]
    right_side_elems = right_side_elems.split()
    middle_elems_dict['price'] = int(right_side_elems[0])

    df = pd.DataFrame(middle_elems_dict, index=[count])
    df_list.append(df)
    
    #print(df)
    count+=1
In [ ]:
 
In [89]:
catted_df = pd.concat(df_list)
In [90]:
for k, v in item_dict.items():
    
    item_df = catted_df[catted_df['type_id'] == v]

    #print(item_df)
In [91]:
cdf_1 = catted_df[['type_id', 'price']]
cdf_1.groupby('type_id').describe().sort_values(('price', '50%'), ascending=False).round(1)
Out[91]:
price
count mean std min 25% 50% 75% max
type_id
cartbody 3.0 4800.0 0.0 4800.0 4800.0 4800.0 4800.0 4800.0
sledge 4.0 4811.2 894.4 4050.0 4162.5 4597.5 5246.2 6000.0
pickaxe 4.0 3350.0 479.6 2700.0 3150.0 3450.0 3650.0 3800.0
spade 3.0 2916.7 1926.4 950.0 1975.0 3000.0 3900.0 4800.0
hammer 6.0 3161.8 2494.9 1100.0 1977.8 2200.5 3225.0 8000.0
goldpan 4.0 2024.8 977.4 1500.0 1521.8 1554.5 2057.5 3490.0
axe 2.0 1549.5 70.0 1500.0 1524.8 1549.5 1574.2 1599.0
saw 3.0 1791.7 1019.3 950.0 1225.0 1500.0 2212.5 2925.0
shovel 1.0 1305.0 NaN 1305.0 1305.0 1305.0 1305.0 1305.0
tile 4.0 502.0 147.8 330.0 420.0 500.0 582.0 678.0
brick 3.0 440.0 115.3 320.0 385.0 450.0 500.0 550.0
steelblock 4.0 400.5 90.8 290.0 357.5 402.0 445.0 508.0
steelplate 4.0 406.5 100.4 297.0 359.2 395.0 442.2 539.0
stoneblock 6.0 367.3 51.0 315.0 329.8 359.5 390.0 450.0
woodgirder 6.0 363.3 63.0 279.0 351.8 358.0 359.8 475.0
board 7.0 156.1 50.2 97.0 124.5 145.0 179.5 243.0
ore 9.0 120.8 36.6 90.0 95.0 107.0 140.0 200.0
coal 9.0 108.0 36.3 79.0 85.0 100.0 110.0 200.0
stoneplate 5.0 119.8 49.7 80.0 85.0 99.0 135.0 200.0
clay 21.0 94.0 43.7 60.0 60.0 80.0 99.0 200.0
wood 7.0 15.6 15.2 9.0 9.0 10.0 11.0 50.0
stone 10.0 8.2 3.5 4.0 6.0 7.5 9.8 15.0
nail 3.0 8.0 1.7 7.0 7.0 7.0 8.5 10.0
In [ ]:
 
In [92]:
#strftime("%Y/%m/%d %H:%M:%S")
catted_df['date'] = strftime("%Y/%m/%d %H:%M:%S")
#catted_df
In [93]:
strftime("%Y-%m-%d %H:%M:%S")

catted_df.to_csv(os.path.join(r'C:\Users\matth\bokeh_snow_tracker\market_reports_wax', 'market_report_' + strftime("%Y%m%d_%H%M%S") + '.csv'))
In [ ]:
 
In [ ]:
 
In [94]:
type_id_list = catted_df['type_id'].unique().tolist()
In [95]:
csvs = os.listdir(r'C:\Users\matth\bokeh_snow_tracker\market_reports_wax')
In [96]:
csv_dfs_list = []
In [97]:
for csv in csvs:
    csv = os.path.join(r'C:\Users\matth\bokeh_snow_tracker\market_reports_wax', csv )

    df_a = pd.read_csv(csv)
    df_a['date'] = pd.to_datetime(df_a.date, dayfirst=False, yearfirst=True)+ pd.Timedelta('7 hours')
    #df_a.set_index('date', inplace=True)
    df_a = df_a[df_a['price'] < 10000000]
    df_b = df_a.groupby(['type_id']).agg(['median'])    
    #df_b = df_a.groupby(['type_id']).agg(['min']) 
    
    df_b['date'] = df_a['date'].max()
    csv_dfs_list.append(df_b)
In [98]:
master_csvs_df = pd.concat(csv_dfs_list)
master_csvs_df['item'] = master_csvs_df.index
#master_csvs_df.set_index('date', inplace=True)
In [99]:
#master_csvs_df = master_csvs_df[master_csvs_df['item'] == 'axe']
#master_csvs_df.columns
In [100]:
master_csvs_df.to_csv('master_df_example.csv')


#
In [101]:
def create_bokeh_item_time_series(df, task_list, color_list, title):
    
    def datetime_formatter(x):
        return  np.array(x, dtype=np.datetime64)

    if task_list == raw_materials_list:
        fig_y_range = (0, 200)
    elif task_list == refined_materials_list:
        fig_y_range = (0, 2000)
    elif task_list == tools_list:
        fig_y_range = (0, 25000)
    elif task_list == transport_list:
        fig_y_range = (0, 100000)
    
    from bokeh.palettes import Spectral11
    p_mpw = figure(y_range = fig_y_range,
                   plot_width = 800, 
                   plot_height = 400,
                   sizing_mode = 'scale_width', 
                x_axis_type="datetime", 
                toolbar_location='right', 
                title= title, 
                active_drag="pan", 
                tools="reset,wheel_zoom,box_zoom,save,pan", 
                  #y_axis_type="log",  
        output_backend="webgl")

    for task, color in zip(task_list, color_list):
    
        df_2 = df[df['item'] == task]
        
        
            
        #print(df_2)
    
        source = ColumnDataSource(data={'date' : datetime_formatter(df_2['date']),
                                                    'price' : df_2['price']['median'], 
                                       'item': df_2['item']})

        
        p_mpw.line(x='date', y='price', line_width=3, line_dash='solid', color=color, source=source,legend=task )
     
        
        
        p_mpw.add_tools(HoverTool(tooltips=[('item','@item'),('date','@date{%c}'), ( 'price',  '@{price}{0.0[0]}' ), ],
            formatters={'date':'datetime', 'price':'numeral', 'item':'printf'}, toggleable=False))
    

    p_mpw.legend.location =  'center_left'
    p_mpw.legend.label_text_font_size = '7pt'
    p_mpw.legend.spacing = 0
    p_mpw.legend.label_height = 2
    p_mpw.legend.click_policy="hide"

    p_mpw.title.text_font_size = '15pt'
    p_mpw.title.align = "center"
    
    
    p_mpw.yaxis.axis_label="Price"
    p_mpw.yaxis.axis_label_text_font_size = "15pt"
    p_mpw.yaxis.major_label_text_font_size = "15pt"
    p_mpw.yaxis.axis_label_text_font = "times"
    p_mpw.yaxis.axis_label_text_color = "black"

    
    p_mpw.xaxis.axis_label="Date"
    p_mpw.xaxis.axis_label_text_font_size = "15pt"
    p_mpw.xaxis.major_label_text_font_size = "15pt"
    p_mpw.xaxis.axis_label_text_font = "times"
    p_mpw.xaxis.axis_label_text_color = "black"
    
    from bokeh.models import NumeralTickFormatter
    p_mpw.yaxis[0].formatter = NumeralTickFormatter(format="0.0")
    #p_mpw.xaxis[0].formatter = NumeralTickFormatter(format="0.0")
    
    #output_file("INTERACTIVE_DUKE_TRACKER_MIDWEST_MILES_PER_WEEK_" + current_time + ".html")
    p_mpw.min_border = 3
    cwd = os.getcwd()
    

    #global bokeh_mpw_html
    
    
    #bokeh_mpw_html =  os.path.join(cwd , "INTERACTIVE_DUKE_TRACKER_MIDWEST_MILES_PER_WEEK_" + current_time + ".html")
    
    #save(p_mpw)
    
    output_notebook()
    

               
    show(p_mpw)
    
    
'''   
from bokeh.palettes import Category20              
#color_list = Category20[20] + Category20[20] 
color_list = list(task_color_dic.values())
dash_list = list(dash_dic.values())
create_bokeh_item_time_series(master_csvs_df, task_list, color_list, title)
''' ;
In [ ]:

In [102]:
master_csvs_df_index_list = master_csvs_df.index.unique().tolist()
    
raw_materials_list = ['clay', 'coal', 'ore', 'stone', 'wood', 'coffee bean']

raw_materials_list = [x for x in raw_materials_list if x in master_csvs_df_index_list]


refined_materials_list = ['board', 'beam', 'brick', 'nail', 'steelblock', 'steelplate', 'stoneblock', 'stoneplate', 'tile', 'woodgirder']

refined_materials_list = [x for x in refined_materials_list if x in master_csvs_df_index_list]

tools_list = ['axe', 'goldpan', 'hammer', 'pickaxe', 'saw', 'shovel', 'sledge', 'spade']

tools_list = [x for x in tools_list if x in master_csvs_df_index_list]

transport_list = ['cartbody', 'wagon']

transport_list = [x for x in transport_list if x in master_csvs_df_index_list]

task_list = raw_materials_list + refined_materials_list + tools_list + transport_list
In [ ]:

In [ ]:
 
In [103]:
task_list = raw_materials_list + refined_materials_list + tools_list + transport_list
In [104]:
from bokeh.palettes import Category20              
color_list = Category20[20] + Category20[20] 
title = 'Resources Median Price'

resources_bokeh = create_bokeh_item_time_series(master_csvs_df, raw_materials_list, color_list, title)
Loading BokehJS ...
In [ ]:
 
In [ ]:

In [ ]:
 
In [105]:
        
#color_list = Category20[20] + Category20[20] 
title = 'Materials Median Price'
create_bokeh_item_time_series(master_csvs_df, refined_materials_list, color_list, title)
Loading BokehJS ...
In [106]:
             
color_list = Category20[20] + Category20[20] 
title = 'Tools Median Price'
create_bokeh_item_time_series(master_csvs_df, tools_list, color_list, title)
Loading BokehJS ...
In [107]:
             
color_list = Category20[20] + Category20[20] 
title = 'Transport Median Price'
create_bokeh_item_time_series(master_csvs_df, transport_list, color_list, title)
Loading BokehJS ...
In [ ]:
 
In [ ]:
 
In [54]:
    

os.system('jupyter nbconvert --to html prospectors_market_report.ipynb')
Out[54]:
0
In [ ]: