File size: 1,611 Bytes
5a97e5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pandas as pd


class DemandAssessment:
    def __init__(self):
        self.raw_score = pd.read_csv("data/demand_raw.csv")

    def print_data(self):
        return self.raw_score

    def get_demand_score(self, region, city, district):
        def calculate_normalized_score(score: float, flag: str ) -> str:
            map = dict(city=[0, 2.70238], region=[0, 1.234568], country=[0, 0.289575])
            threshold = map[flag]
            if score >= threshold[1]:
                return "High"
            elif threshold[0] < score < threshold[1]:
                return "Moderate"
            else:
                return "Low"

        if region:
            temp = self.raw_score[
                (self.raw_score["Region"] == region) &
                (self.raw_score["City"] == city) &
                (self.raw_score["District"] == district)
                ]
        else:
            temp = self.raw_score[
                (self.raw_score["City"] == city) &
                (self.raw_score["District"] == district)
                ]
        temp = temp.iloc[0]

        return {
            "City_Normalized_Score": temp["City Scaled Score"],
            "Region_Normalized_Score": temp["Region Scaled Score"],
            "Country_Normalized_Score": temp["Region Scaled Score"],
            "City_Demand_Label": calculate_normalized_score(temp["City Scaled Score"], "city"),
            "Region_Demand_Label": calculate_normalized_score(temp["Region Scaled Score"], "region"),
            "Country_Demand_Label": calculate_normalized_score(temp["Region Scaled Score"], "country"),
        }