Exemplo n.º 1
0
def __filter_trends(main,errors):
    
    final_trends = {}
        
    used_label = {}
    product_errors = {}
    country_errors = {}
    
    for error in errors:
        product_errors[error.split(",")[2]] = True
        country_errors[error.split(",")[3]] = True
    for trend in main.interesting_trends:
        
        trendline = trend.split("$")[0].split("-")[-1]
        
        
        year = Tools.getTrendYear(trendline)

        continue_bool = False
        
        
        
        try:
            if (year < used_label[trend.split("-")[0]]):
                continue_bool = True
         
                
        except:
            continue_bool = True 
        if (continue_bool):
            try:
               
                float(trend.split("-")[0])
                
                try:
                    product_errors[trend.split("-")[0]]          
                except:    
                    label =  str(year) + "," + str(last_year) + "," + trend.split("-")[0] + ",," + "Import"
            
                                            
                    used_label[trend.split("-")[0]] = year
                    
                    if (final_trends.get(label,0) != 0):
                        print ("Trend Found",label)
                        print ("Trend Found",label)
                        print ("Trend Found",label)
                        print ("Trend Found",label)

                    final_trends[label] = final_trends.get(label,0) + main.interesting_trends[trend]
    
            except:
                try:
                    country_errors[trend.split("-")[0]]
                except:
                    label = str(year) + "," + str(last_year) + ",," + trend.split("-")[0] + "," + "Import"
                    
                    used_label[trend.split("-")[0]] = year
                    
                    final_trends[label] = final_trends.get(label,0) + main.interesting_trends[trend]
    return final_trends
Exemplo n.º 2
0
def __findInterestingTrends ():
    
    main.interesting_trends = {}
    
    # First it acquires the trends from the product trends 
#     print (relative_threashold)
    
    for trend in main.product_trends:
        print (trend)
        product = trend.split("-")[0]
        trendline = trend.split("-")[1]
        
        trend_val = main.product_trends[trend]

        year = Tools.getTrendYear(trendline)
         


#         if (abs(trend_val)/(last_year - year + 1) >= )

        # If the value of the trend (i.e. -.5 or a 50% decrease) times the size of the market (i.e. $1 billion dollars) is greater than the 
        # absolute threshold then insert the value into interesting trends
        
        
        if (abs(trend_val)/(last_year - year + 1) >= main.relative_threashold):

            start = main.getProduct(product, year)
#             print(start)
            end = main.getProduct(product, last_year)

            net = end -start
#             print ("Absolute",absolute_threshold,abs(net))

            if(abs(net) > main.absolute_threshold and start > main.absolute_threshold):
                
#                 print ("Absolute",absolute_threshold,abs(net))
                
                if (len(product)==4):
                    market_val = 1.1
                else:
                    total = 0 
                    for y in range (year,last_year):
                        total += main.getProduct(product[:-2],y)
                    market_average = total/(last_year - year + 1)

                    total = 0 
                    for y in range (year,last_year):
                        total += main.getProduct(product,y)

                    product_average = total/(last_year - year + 1)
                    if (product_average == 0):
                        market_val = 0
                    else:
                        market_val = product_average/market_average
#                     print (market_val)
                if (market_val > main.market_threshold):
                    label = "%s$%s" % (trend,net)
#                     print ("Absolute",absolute_threshold,abs(net),label)
                    main.interesting_trends[label] = trend_val
            
            
    for trend in main.country_trends:
                
        trend_val = main.country_trends[trend]       

        trendline = trend.split("-")[1]
            
        country = trend.split("-")[0]
                     
        year = main.getTrendYear(trendline)
#         
#         if (not year):
#             print ("Trend:",trend)
                 
        if (abs(trend_val)/(last_year - year + 1) >= main.relative_threashold):


                       
            start = main.getCountry(country,year)
            
            end = main.getCountry(country,last_year)
    
            net = end - start
                    
    
            # If the value of the trend (i.e. -.5 or a 50% decrease) times the size of the market (i.e. $1 billion dollars) is greater than the 
            # absolute threshold then insert the value into interesting trends
            
            if (abs(net) > main.absolute_threshold and start > main.absolute_threshold):

#                 print ("Absolute",absolute_threshold,abs(net))
                
                label = "%s$%s" % (trend,net)
                
#                 print ("Absolute",absolute_threshold,abs(net),label)

                main.interesting_trends[label] = trend_val
    
    return main.interesting_trends