Rev 2657 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
import mathdef getscore(struct):score = 0.0battery_type_score = 0.0twog_talktime_score = 0.0threeg_talktime_score = 0.0twog_standbytime_score = 0.0threeg_standbytime_score = 0.0usage_time_score = 0.0category = struct.get("category")min_battery_capacity = 800max_battery_capacity = 1800if category == "Tablets":min_battery_capacity = 1000max_battery_capacity = 5000if struct.has_key("features") :features = struct.get("features")battery_capacity = 0.0last = "0"battery_type = features.get("Battery type")battery_type = battery_type[0]battery_type = battery_type.split(" ")print battery_typefor part in battery_type:if part.find("mAh") > -1:try:battery_capacity = float(last)except:battery_capacity = 1200print `last`last = partprint "battery_capacity" + `battery_capacity`if battery_capacity < min_battery_capacity :battery_type_score = 3elif battery_capacity > max_battery_capacity :battery_type_score = 10else :battery_type_score = (battery_capacity - min_battery_capacity)/(max_battery_capacity-min_battery_capacity)*7.0battery_type_score = battery_type_score + 3.0if features.has_key("Usage time") :usage_time = features.get("Usage time")usage_time = usage_time[0]usage_time = usage_time.split(" ")usage_time = float(usage_time[0])if usage_time > 10 :usage_time_score = 10else:usage_time_score = usage_timeif struct.has_key("childrenslides") :childrenslides = struct.get("childrenslides")if childrenslides.has_key("Capacity") :capacity = childrenslides.get("Capacity")if capacity.has_key("features") :features = capacity.get("features")if capacity.has_key("childrenslides") :childrenslides = capacity.get("childrenslides")if childrenslides.has_key("Talk time") :talktime = childrenslides.get("Talk time")if talktime.has_key("features") :features = talktime.get("features")# Capacity > Talk time > 2G : <5 - 0.5, <10 - 1, >10 - 1.5if features.has_key("2G") :twog = features.get("2G")if len(twog) > 0 :twog = twog[0]twog = twog.split(" ")twog = float(twog[0])print "twog=" + `twog`if twog < 3 :twog_talktime_score = 3.0elif twog >= 15 :twog_talktime_score = 10.0else :twog_talktime_score = 3 + (twog - 3) / (15 - 3) * 7# Capacity > Talk time > 3G : <5 - 0.5, <10 - 1, >10 - 1.5if features.has_key("3G") :threeg = features.get("3G")if len(threeg) > 0 :threeg = threeg[0]threeg = threeg.split(" ")threeg = float(threeg[0])print "threeg=" + `threeg`if threeg < 2 :threeg_talktime_score = 3.0elif threeg >= 8 :threeg_talktime_score = 10.0else :threeg_talktime_score = 3.0 + (threeg - 3) / (8 - 2) * 7.0if childrenslides.has_key("Standby time") :standbytime = childrenslides.get("Standby time")if standbytime.has_key("features") :features = standbytime.get("features")# Capacity > Standby time > 2G : <10 - 0.5, <20 - 1, >20 - 1.5if features.has_key("2G") :twog = features.get("2G")if len(twog) > 0 :twog = twog[0]twog = twog.split(" ")twog = float(twog[0])print "twog=" + `twog`if twog < 5 :twog_standbytime_score = 2.0elif twog >= 30 :twog_standbytime_score = 10.0else :twog_standbytime_score = 2 + (twog - 5) / (30 - 5) * 8# Capacity > Standby time > 3G : <10 - 0.5, <20 - 1, >20 - 1.5if features.has_key("3G") :threeg = features.get("3G")if len(threeg) > 0 :threeg = threeg[0]threeg = threeg.split(" ")threeg = float(threeg[0])print "threeg=" + `threeg`if threeg < 5 :threeg_standbytime_score = 2.0elif threeg >= 30 :threeg_standbytime_score = 10.0else :threeg_standbytime_score = 2 + (threeg - 5) / (30 - 5) * 8print "battery_type_score" + `battery_type_score`print "twog_talktime_score" + `twog_talktime_score`print "threeg_talktime_score" + `threeg_talktime_score`print "twog_standbytime_score" + `twog_standbytime_score`print "threeg_standbytime_score" + `threeg_standbytime_score`if category == "Tablets":score = (100*battery_type_score)/100.0elif usage_time_score != 0:score = (40*battery_type_score + 60*usage_time_score)/100elif threeg_talktime_score == 0:score = (40*battery_type_score + 30*twog_talktime_score + 30*twog_standbytime_score )/100else :score = (40*battery_type_score + 20*twog_talktime_score + 10*threeg_talktime_score + 20*twog_standbytime_score + 10*threeg_standbytime_score)/100return score