from django.db import models
import os, errno

from api.utils import *
algoType = [
    ('optimize', 'optimize'),
    ('group', 'group'),
    ('predict', 'predict'),
]

class AlgorithmManager(models.Manager):
    def statistic(self, user):
      results = user.own_plans.all()
      return {
          'amount': len(results),
      }

class Algorithm(models.Model):
    name = models.CharField(default="", max_length=32)
    type = models.CharField(choices=algoType, max_length=16)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)
    
    objects = AlgorithmManager()

    class Meta:
        app_label = 'api'