Skip to content

Instantly share code, notes, and snippets.

@wetmore
Created March 30, 2020 16:27
Show Gist options
  • Save wetmore/c67a4411e9c9169f64bd7bb236e75ee4 to your computer and use it in GitHub Desktop.
Save wetmore/c67a4411e9c9169f64bd7bb236e75ee4 to your computer and use it in GitHub Desktop.
d
from django.conf import settings
from django.db import models
# A Batch represents one batch, and may be assigned to multiple
# users.
class Batch(models.Model):
name = models.CharField(max_length=200)
assigned_users = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True)
def __str__(self):
return "%s" % (self.name)
class Meta:
verbose_name_plural = "Batches"
# An Image represents a single row in the uploaded batch CSV.
class Image(models.Model):
name = models.CharField(max_length=200)
survey = models.CharField(max_length=200)
key = models.CharField(max_length=200)
batch = models.ForeignKey(Batch, on_delete=models.CASCADE)
def __str__(self):
return "%s" % (self.name)
# An AssignedBatch represents a batch of images assigned to one user. It holds
# data about the progress a user has made in classifying images.
class AssignedBatch(models.Model):
name = models.CharField(max_length=200)
parent_batch = models.ForeignKey(Batch, on_delete=models.CASCADE)
progress = models.IntegerField(default=-1)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE,)
def __str__(self):
return "{} - {}".format(self.name, self.user.username)
class Meta:
verbose_name_plural = "Assigned batches"
# An AssignedImage represents an image assigned to a particular user, and
# features they have found in the image.
class AssignedImage(models.Model):
name = models.CharField(max_length=200)
batch = models.ForeignKey(AssignedBatch, on_delete=models.CASCADE)
index_in_batch = models.IntegerField()
key = models.CharField(max_length=200)
survey = models.CharField(max_length=200)
end_terminal = models.BooleanField("End terminal present", default=False)
longitudinal_barrier = models.BooleanField(
"Longitudinal barrier present", default=False
)
mile_marker = models.BooleanField("Mile marker present", default=False)
oddfunny = models.BooleanField("Odd/funny situation present", default=False)
other_sign = models.BooleanField("Other sign present", default=False)
rumble_strip = models.BooleanField("Rumble strip present", default=False)
seen = models.BooleanField(
"The person classifying has seen this image", default=False
)
def __str__(self):
return "%s" % (self.name)
class Meta:
ordering = ["index_in_batch"]
class CompletedImage(models.Model):
survey = models.CharField(max_length=200)
name = models.CharField(max_length=200)
key = models.CharField(max_length=200)
user_id = models.CharField(max_length=200)
end_terminal = models.BooleanField("End terminal present", default=False)
longitudinal_barrier = models.BooleanField(
"Longitudinal barrier present", default=False
)
mile_marker = models.BooleanField("Mile marker present", default=False)
oddfunny = models.BooleanField("Odd/funny situation present", default=False)
other_sign = models.BooleanField("Other sign present", default=False)
rumble_strip = models.BooleanField("Rumble strip present", default=False)
def __str__(self):
return "%s" % (self.name)
class Meta:
ordering = ["name"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment