def get_car_stats_between_dates_in_stores(start, end, store_id, stats_names=None): intent_cars_dict = LookupValue.find_all_in_dict_by_lookup_name_of_store_from_cache( long(store_id), 'intent-car') data_per_category = {} for stats_name in stats_names: data_per_category[stats_name] = car_stats_meta.get(stats_name)( start, end, store_id) result = [] for code, value in intent_cars_dict.iteritems(): data = {} ignore = False for stats_name in stats_names: stats = data_per_category.get(stats_name).get(code, 0) if stats == 0: ignore = True continue data[stats_name] = stats if not ignore: stats = StoreStatsData() stats.category = value.value stats.data = data result.append(stats) return result
def update_car_series(mapper, connection, target): if target.ordered_car_id: lookupvalue_dict = LookupValue.find_all_in_dict_by_lookup_name_of_store_from_cache( long(target.store_id), 'intent-car') lookupvalue = lookupvalue_dict.get(target.ordered_car_id) if lookupvalue: target.ordered_car_name = lookupvalue.value target.ordered_car_series = lookupvalue.section
def refresh_lookup(store_id): data = request.json if data is None or not data.get('name'): abort(400, description=gettext('invalid json request')) cache.delete_memoized( LookupValue.find_all_in_dict_by_lookup_name_of_store_from_cache, LookupValue, long(store_id), data.get('name')) return LookupValue.find_all_in_dict_by_lookup_name_of_store_from_cache( store_id, data.get('name'))
def convert_car_code(store_id, isr_car_codes): car_codes = parse_comma_seperated_args(isr_car_codes) if car_codes and len(car_codes) > 0: car_code = car_codes[0] # use the first one lookups = LookupValue.find_all_in_dict_by_lookup_name_of_store_from_cache( long(store_id), 'intent-car') lookup = lookups.get(car_code) if lookup: return lookup.vendor_code, lookup.vendor_section, lookup.vendor_value return '', '', ''
def lookup_str(value, store_id, lookup_name): if not value: return '' lookupvalue_dict = LookupValue.find_all_in_dict_by_lookup_name_of_store_from_cache( long(store_id), lookup_name) lookupvalue = lookupvalue_dict.get(value, None) if not lookupvalue: return '' elif lookupvalue == 'none': return u'无' else: return lookupvalue.value
def lookup_sections_by_codes(store_id, codes, lookup_name): from application.models.lookup import LookupValue lookupvalue_dict = LookupValue.find_all_in_dict_by_lookup_name_of_store_from_cache(long(store_id), lookup_name) if codes and codes.strip() and lookupvalue_dict and len(lookupvalue_dict) > 0: codes_arr = codes.split(',') sections = set() for code in codes_arr: lookupvalue = lookupvalue_dict.get(code, None) if lookupvalue and lookupvalue.section: sections.add(lookupvalue.section) if len(sections) > 0: return ','.join(sections) return ''
def get_unordered_customers_count_by_intent_level(start, end, store_id): uoc_stats = Reception.get_unordered_customers_count_by_intent_level_between_dates_in_store( start, end, store_id) uoc_stats = {s[1]: s[0] for s in uoc_stats} intent_levels_dict = LookupValue.find_all_in_dict_by_lookup_name_of_store_from_cache( long(store_id), 'intent-level') result = [] for code, value in intent_levels_dict.iteritems(): stats = uoc_stats.get(code, 0) if stats != 0: result.append((value.value, stats)) return result
def get_rx_customers_count_by_car_models(start, end, store_id): rx_customers_by_car = Reception.get_rx_customers_count_by_car_models_bwteeen_dates_in_stores( start, end, store_id) intent_cars_dict = LookupValue.find_all_in_dict_by_lookup_name_of_store_from_cache( long(store_id), 'intent-car') result = dict() for code, value in intent_cars_dict.iteritems(): count = 0 for stats in rx_customers_by_car: # need to calc count again since there would be multiple intent cars seperated by comma. if code in stats[1]: count += stats[0] if count > 0: result[code] = count return result
def get_selections_by_lookup_name(store_id, lookup_name): from application.models.lookup import LookupValue lookupvalues_list = LookupValue.find_all_in_dict_by_lookup_name_of_store_from_cache( long(store_id), lookup_name).values() lookupvalues_list.sort(key=lambda value: value.id) return [(value.code, value.value) for value in lookupvalues_list]