Spaces:
Sleeping
Sleeping
Vela
commited on
Commit
·
d64edc6
1
Parent(s):
22b9c3e
Update project
Browse files
backend/api/__pycache__/main.cpython-312.pyc
CHANGED
Binary files a/backend/api/__pycache__/main.cpython-312.pyc and b/backend/api/__pycache__/main.cpython-312.pyc differ
|
|
backend/api/main.py
CHANGED
@@ -16,12 +16,12 @@ def display_data():
|
|
16 |
@app.get("/ShowAllContinents")
|
17 |
def display_continents():
|
18 |
continents = home_page.display_continents(df)
|
19 |
-
return continents
|
20 |
|
21 |
@app.get("/ShowAllCountries")
|
22 |
def display_countries():
|
23 |
countries = home_page.display_countries(df)
|
24 |
-
return countries
|
25 |
|
26 |
@app.get("/ShowContinentStats/{attribute}/{stat_type}")
|
27 |
def display_continent_stats(attribute:str, stat_type:str):
|
@@ -31,4 +31,14 @@ def display_continent_stats(attribute:str, stat_type:str):
|
|
31 |
@app.get("/ShowCountryStats/{attribute}/{stat_type}")
|
32 |
def display_country_stats(attribute : str, stat_type : str):
|
33 |
country_stats = home_page.country_stat(df, attribute,stat_type)
|
34 |
-
return country_stats
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
@app.get("/ShowAllContinents")
|
17 |
def display_continents():
|
18 |
continents = home_page.display_continents(df)
|
19 |
+
return continents
|
20 |
|
21 |
@app.get("/ShowAllCountries")
|
22 |
def display_countries():
|
23 |
countries = home_page.display_countries(df)
|
24 |
+
return countries
|
25 |
|
26 |
@app.get("/ShowContinentStats/{attribute}/{stat_type}")
|
27 |
def display_continent_stats(attribute:str, stat_type:str):
|
|
|
31 |
@app.get("/ShowCountryStats/{attribute}/{stat_type}")
|
32 |
def display_country_stats(attribute : str, stat_type : str):
|
33 |
country_stats = home_page.country_stat(df, attribute,stat_type)
|
34 |
+
return country_stats
|
35 |
+
|
36 |
+
@app.get("/ShowContinentWiseData/{attribute}")
|
37 |
+
def display_cont_wise_stats(attribute : str):
|
38 |
+
conts_stats = home_page.get_continent_wise_stat(df,attribute)
|
39 |
+
return conts_stats
|
40 |
+
|
41 |
+
@app.get("/ShowCountryData/{country}/{attribute}")
|
42 |
+
def display_country_wise_stats(country : str, attribute : str):
|
43 |
+
conts_stats = home_page.get_country_wise_stat(df, country, attribute)
|
44 |
+
return conts_stats
|
backend/modules/__pycache__/home_page.cpython-312.pyc
CHANGED
Binary files a/backend/modules/__pycache__/home_page.cpython-312.pyc and b/backend/modules/__pycache__/home_page.cpython-312.pyc differ
|
|
backend/modules/home_page.py
CHANGED
@@ -7,9 +7,6 @@ from utils import logger
|
|
7 |
|
8 |
file_path = "./world_population.csv"
|
9 |
|
10 |
-
# file_path = "C:/Users/Vijay/Downloads/world_population.csv"
|
11 |
-
# data_frame = pd.read_csv(file_path)
|
12 |
-
|
13 |
def process_data():
|
14 |
try:
|
15 |
logger.log("I'm going to read the csv")
|
@@ -23,12 +20,14 @@ def process_data():
|
|
23 |
def display_continents(dataframe):
|
24 |
continents = dataframe['Continent'].unique()
|
25 |
logger.log("Displaying the list of continents in the data")
|
26 |
-
|
|
|
27 |
|
28 |
def display_countries(dataframe):
|
29 |
countries = dataframe['Country'].values
|
|
|
30 |
logger.log("Displaying the list of countries in the data")
|
31 |
-
return
|
32 |
|
33 |
def continent_stat(dataframe, attribute="Population", stat_type="highest"):
|
34 |
try:
|
@@ -49,8 +48,8 @@ def continent_stat(dataframe, attribute="Population", stat_type="highest"):
|
|
49 |
|
50 |
else:
|
51 |
raise ValueError("Invalid stat_type. Use 'highest' or 'lowest'.")
|
52 |
-
|
53 |
-
return
|
54 |
|
55 |
except Exception as e:
|
56 |
logger.log(f"Error in continent_stat: {str(e)}")
|
@@ -65,66 +64,19 @@ def country_stat(dataframe, attribute : str = "Population", stat_type :str = "hi
|
|
65 |
|
66 |
country = dataframe['Country'][index]
|
67 |
requested_attribute = dataframe[attribute][index]
|
68 |
-
result = {country:requested_attribute.item()}
|
69 |
logger.log(f"Displaying the country with {stat_type} {attribute} in the data")
|
70 |
return result
|
71 |
except Exception as e:
|
72 |
return f"Unable to fetch the data. Error {e}"
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
# def list_country_by_continent(dataframe,continent):
|
77 |
-
# try:
|
78 |
-
# df_countries = dataframe[dataframe['Continent'] == continent]
|
79 |
-
# countries= df_countries['Country'].to_list()
|
80 |
-
# logger.log("Separated data by continent")
|
81 |
-
# return countries
|
82 |
-
# except Exception as e:
|
83 |
-
# return f"{e}"
|
84 |
-
|
85 |
-
# def get_stat_by_continent(df ,continent: str, data_type: str, stat: str , ):
|
86 |
-
|
87 |
-
# if continent.lower() == "NorthAmerica".lower():
|
88 |
-
# continent = "North America"
|
89 |
-
# if continent.lower() == "SouthAmerica".lower():
|
90 |
-
# continent = "South America"
|
91 |
-
|
92 |
-
# valid_stats = ['max', 'min', 'mean' , 'sum' , 'count']
|
93 |
-
# if stat not in valid_stats:
|
94 |
-
# return f"Invalid stat. Please use one of the following: {valid_stats}."
|
95 |
-
|
96 |
-
# continent_population_stats = df.groupby('Continent')[data_type].agg(
|
97 |
-
# Maximum='max', Minimum='min', Average = 'mean',Total='sum' , Number_of_Countries = 'count')
|
98 |
-
|
99 |
-
# continent_countries = df[df['Continent'] == continent]
|
100 |
-
|
101 |
-
# if continent not in continent_population_stats.index:
|
102 |
-
# return f"Continent '{continent}' not found in the data."
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
# population_value = country_id[data_type]
|
109 |
-
# return f"{continent}'s {stat} {data_type} is {int(population_result)}. Country: {country_name} , {data_type} :{population_value}"
|
110 |
-
# if stat == 'min':
|
111 |
-
# population_result = continent_population_stats.loc[continent]['Minimum']
|
112 |
-
# country_id = continent_countries.loc[continent_countries[data_type].idxmin()]
|
113 |
-
# country_name = country_id['Country']
|
114 |
-
# population_value = country_id[data_type]
|
115 |
-
# return f"{continent}'s {stat} {data_type} is {int(population_result)}. Country: {country_name} , {data_type} :{population_value}"
|
116 |
-
# if stat == 'mean':
|
117 |
-
# population_result = continent_population_stats.loc[continent]['Average']
|
118 |
-
# return f"{continent}'s average {data_type} is {int(population_result)}"
|
119 |
-
# if stat == 'sum':
|
120 |
-
# population_result = continent_population_stats.loc[continent]['Total']
|
121 |
-
# return f"{continent}'s total {data_type} is {int(population_result)}"
|
122 |
-
# if stat == 'count' :
|
123 |
-
# population_result = continent_population_stats.loc[continent]['Number_of_Countries']
|
124 |
-
# return f"Total countries in {continent} is {int(population_result)}"
|
125 |
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
7 |
|
8 |
file_path = "./world_population.csv"
|
9 |
|
|
|
|
|
|
|
10 |
def process_data():
|
11 |
try:
|
12 |
logger.log("I'm going to read the csv")
|
|
|
20 |
def display_continents(dataframe):
|
21 |
continents = dataframe['Continent'].unique()
|
22 |
logger.log("Displaying the list of continents in the data")
|
23 |
+
continents_df = pd.DataFrame(continents, columns=["Continent"])
|
24 |
+
return continents_df
|
25 |
|
26 |
def display_countries(dataframe):
|
27 |
countries = dataframe['Country'].values
|
28 |
+
countries_df = pd.DataFrame(countries, columns=["Country"])
|
29 |
logger.log("Displaying the list of countries in the data")
|
30 |
+
return countries_df
|
31 |
|
32 |
def continent_stat(dataframe, attribute="Population", stat_type="highest"):
|
33 |
try:
|
|
|
48 |
|
49 |
else:
|
50 |
raise ValueError("Invalid stat_type. Use 'highest' or 'lowest'.")
|
51 |
+
result = {attribute : {continent: value}}
|
52 |
+
return result
|
53 |
|
54 |
except Exception as e:
|
55 |
logger.log(f"Error in continent_stat: {str(e)}")
|
|
|
64 |
|
65 |
country = dataframe['Country'][index]
|
66 |
requested_attribute = dataframe[attribute][index]
|
67 |
+
result = {attribute:{country:requested_attribute.item()}}
|
68 |
logger.log(f"Displaying the country with {stat_type} {attribute} in the data")
|
69 |
return result
|
70 |
except Exception as e:
|
71 |
return f"Unable to fetch the data. Error {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
+
def get_continent_wise_stat(data_frame, attribute):
|
74 |
+
if "Continent" in data_frame.columns and "Population" in data_frame.columns:
|
75 |
+
continent_data = data_frame.groupby("Continent")[attribute].sum().reset_index()
|
76 |
+
return continent_data.to_dict()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
+
def get_country_wise_stat(data_frame, country, attribute):
|
79 |
+
country_df = data_frame[data_frame["Country"]== country]
|
80 |
+
data = country_df[attribute].item()
|
81 |
+
result = {country:{attribute:data}}
|
82 |
+
return result
|