Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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):
def __str__ (self):
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"])
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