# print("%s-%s" % (year,product),value) return value except: # print("%s-%s" % (year,product)) return 0; def getCountry(country, year): try: value = country_values["%s-%s" % (year,country)] return value except: return 0 # This will run through the collected data and return the Total Product for a given year and country def getProductCountry(product,country,year,tag): try: # print (product,country,year,tag) return country_product_values["%s-%s-%s~%s" % (year,country,product,tag)] except: return 0 if __name__ == '__main__': start = time.time() Tools.initilize() file_name = file_location + 'baci92_' Tools.single_thread(Tools.preprocess, first_year, last_year, file_name, False) end = time.time()
def getTrends (file_name,country,product,relative =1,absolute=50000,market=.15,trendline = "All"): global main main = Tools.initilize() global last_year global first_year global country_codes global country_names country_names = main.country_names country_codes = main.country_codes last_year = main.last_year first_year= main.first_year start = time.time() main.product_trends = {} main.country_trends = {} main.product_values = {} main.country_values = {} main.market_trends = {} # absolute_threshold = float(absolute) main.market_threshold = float(market) main.relative_threashold = float(relative) main.absolute_threshold = float(absolute) / (last_year - first_year + 1) print (product,main.absolute_threshold,main.market_threshold,main.trend_threashold,main.relative_threashold,trendline) keys = [] for code in country_codes: if (country) == country_codes[code]: keys.append(code) for code in country_names: if (country) == country_names[code]: keys.append(code) print (keys) Tools.single_thread(Tools.getTotalCountry, first_year, last_year, arg=(file_name,keys)) absolute_threshold = (float(absolute) / (last_year - first_year + 1)) * main.total_country_value print ("Absolute", absolute_threshold) print("Total Country Value", main.total_country_value) Tools.single_thread(__getTrendsPreProcessed,first_year,last_year,arg=(file_name,keys,product,trendline)) # absolute_threshold = float(absolute) * total_country_value main.interesting_trends = {} # for i in interesting_trends: # print ("Interesting Before:",i) __findInterestingTrends() # for i in interesting_trends: # print ("Interesting After:",i); (main,final_errors) = Error_Handler.getErrors(file_name, country, 1.5, absolute_threshold, market, .75, 3, main) end = time.time() print(end - start) return (main,__filter_trends(main,final_errors))