Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created August 28, 2018 16:32
Show Gist options
  • Save chelseatroy/c49902b418d851f02c5aeeb814ddf095 to your computer and use it in GitHub Desktop.
Save chelseatroy/c49902b418d851f02c5aeeb814ddf095 to your computer and use it in GitHub Desktop.
Example of Giant Conditional in Django Model
from __future__ import unicode_literals
from django.conf import settings
from django.db import models
from django.utils import timezone
import numpy as np
from calendar import Calendar
from charts import HeatMap, PieChart
from exceptions import IncompleteDataException
class Visualization(models.Model):
name = models.CharField(primary_key=True, max_length=200)
description = models.TextField()
position = models.IntegerField(default=200)
def __repr__ (self):
return self.name
def __str__ (self):
return self.name
def from_data(name, csvfile):
if name == "infection_rates":
department_instances = []
infection_type = []
with open csvfile as file:
if file["department"] and file["type"]:
department_instances = np.array(file["department"])
infection_type = np.array(file["type"])
else:
return IncompleteDataException("Please include a department and a type column in your CSV.")
map = HeatMap(list(zip(department_instances, infection_type)))
return map.to_svg()
if name == "family_visits":
#...similar rigamarole
if name == "food_requests":
#...similar rigamarole
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment