Skip to content

Commit

Permalink
complete removal of cases class and related logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lrdossan committed Jul 31, 2024
1 parent 0bec404 commit 1368e33
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 72 deletions.
47 changes: 0 additions & 47 deletions caimira/apps/calculator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,52 +376,6 @@ async def get(self, hotel_id, floor_id):
return self.finish(response.body)


class CasesData(BaseRequestHandler):
async def get(self, country):
http_client = tornado.httpclient.AsyncHTTPClient()
try:
country_name = await self.get_country_name(country, http_client)
if not country_name:
return self.finish('Country not found')

cases_data = await self.get_cases_data(country_name, http_client)
if not cases_data:
return self.finish('Data not available')

return self.finish(str(round(cases_data)))
except Exception as e:
print("Something went wrong: %s" % e)
return self.finish('Internal Server Error', status_code=500)

async def get_country_name(self, country_code, http_client):
url = f'https://restcountries.com/v3.1/alpha/{country_code}?fields=name'
try:
response = await http_client.fetch(url)
if response.code != 200:
return None
data = json.loads(response.body)
return data['name']['common'] if 'name' in data else None
except Exception as e:
print("Something went wrong: %s" % e)
return None

async def get_cases_data(self, country_name, http_client):
url = 'https://covid19.who.int/WHO-COVID-19-global-data.csv'
try:
response = await http_client.fetch(url)
if response.code != 200:
return None
data = response.body.decode('utf-8')
df = pd.read_csv(StringIO(data))
cases = df[df['Country'] == country_name]
if cases.empty:
return None
return cases['New_cases'].mean()
except Exception as e:
print("Something went wrong: %s" % e)
return None


class GenericExtraPage(BaseRequestHandler):

def initialize(self, active_page: str, filename: str):
Expand Down Expand Up @@ -517,7 +471,6 @@ def make_app(
(get_root_calculator_url(r'/report-json'), ConcentrationModelJsonResponse),
(get_root_calculator_url(r'/baseline-model/result'), StaticModel),
(get_root_calculator_url(r'/api/arve/v1/(.*)/(.*)'), ArveData),
(get_root_calculator_url(r'/cases/(.*)'), CasesData),
# Generic Pages
(get_root_url(r'/about'), GenericExtraPage, {
'active_page': 'about',
Expand Down
22 changes: 0 additions & 22 deletions caimira/apps/calculator/static/js/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,6 @@ function on_exposure_change() {
if (this.checked) {
getChildElement($(this)).show();
require_fields(this);
if (this.id == "p_probabilistic_exposure") {
// Update geographic_cases
geographic_cases($('[name="location_name"]')[0].value.split(', ')[1]);
};
}
else {
getChildElement($(this)).hide();
Expand Down Expand Up @@ -422,22 +418,6 @@ function show_sensors_data(url) {
}
};

function geographic_cases(location_country_name) {
$.ajax({
url: `${$('#url_prefix').data().calculator_prefix}/cases/${location_country_name}`,
type: 'GET',
success: function (result) {
if (result != 'Country not found') {
$('#geographic_cases').val(result);
result != 'Country not found' ? $('#source_geographic_cases').show() : $('#source_geographic_cases').hide();
}
},
error: function(_, _, errorThrown) {
console.log(errorThrown);
}
});
}

$("#sensors").change(function (el) {
sensor_id = DATA_FROM_SENSORS.findIndex(function(sensor) {
return sensor.RoomId == el.target.value
Expand Down Expand Up @@ -999,8 +979,6 @@ $(document).ready(function () {
$('[name="location_longitude"]').val('6.14275')
}
}
// Handle WHO source message if geographic_cases pre-defined value is modified by user
$('#geographic_cases').change(() => $('#source_geographic_cases').hide());

// When the document is ready, deal with the fact that we may be here
// as a result of a forward/back browser action. If that is the case, update
Expand Down
3 changes: 0 additions & 3 deletions caimira/apps/templates/base/calculator.form.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,6 @@
<div class="col-sm-4"><label class="col-form-label pt-0">New confirmed cases (weekly):</label></div>
<div class="col-sm-6 pl-0 align-self-center">
<input type="number" step="any" id="geographic_cases" class="non_zero form-control" name="geographic_cases" placeholder="Cases (#7-day rolling avg)" min="0">
<small id="source_geographic_cases" class="form-text text-muted" style="display: none">
Source: World Health Organization.
</small>
</div>
</div>
<div class="form-group row">
Expand Down

0 comments on commit 1368e33

Please sign in to comment.