# Path: badges/models.py
# class Badge(models.Model):
#     """ Parent class
#         Base Badge.
#     """
#     name = models.CharField(blank=False, null=False, max_length=255)
#     title = models.CharField(verbose_name=_('Title given with badge (if proceed)'), blank=True,
#                              null=True, max_length=255)
#     description = models.TextField(blank=False, null=False)
#     image = models.ImageField(upload_to='badges', blank=False, null=False)
#     date = models.DateTimeField(verbose_name='Creation date', name="date", auto_now=True)
#     experience = models.DecimalField(verbose_name=_('Experience gained with this badge'),
#                                      default=5.0, decimal_places=2, max_digits=4)
# 
#     def __unicode__(self):
#         return "{}".format(self.name)
# 
#     @property
#     def is_language(self):
#         try:
#             return self.languagebadge
#         except LanguageBadge.DoesNotExist:
#             return False
# 
#     @property
#     def is_fidelity(self):
#         try:
#             return self.fidelitybadge
#         except FidelityBadge.DoesNotExist:
#             return False
# 
#     @property
#     def is_fork(self):
#         try:
#             return self.forkbadge
#         except ForkBadge.DoesNotExist:
#             return False
# 
#     @property
#     def is_license(self):
#         try:
#             return self.licensebadge
#         except LicenseBadge.DoesNotExist:
#             return False
# 
# Path: stats/models.py
# class APIStats(models.Model):
#     """
#         API Usage stats.
#         Number of GitHub API Calls each day
#     """
#     date = models.DateField(verbose_name=_('Day stats'))
#     calls_number = models.IntegerField(verbose_name=_('Number of API Calls'), default=0)
# 
#     def inc_call(self):
#         self.calls_number += 1
# 
#     def inc_multiple(self, number):
#         self.calls += number
# 
#     def __unicode__(self):
#         return 'API Stats of {}'.format(self.date)
# 
# class UserStats(models.Model):
#     """
#         User Stats.
#         Number of New Users each day
#     """
#     date = models.DateField(verbose_name=_('Day stats'))
#     users = models.IntegerField(verbose_name=_("Number of New Users"), default=0)
# 
#     def inc_user(self):
#         self.users += 1
# 
#     def inc_multiple(self, number):
#         self.calls += number
# 
#     def __unicode__(self):
#         return 'User Stats of {}'.format(self.date)
# 
# Path: badges/tasks/Language.py
# def check(user, bytes, language, **kwargs):
# 
# Path: badges/tasks/Fidelity.py
# def check(date, **kwargs):
# 
# Path: badges/tasks/Fork.py
# def check(user, forks, **kwargs):
# 
# Path: badges/tasks/License.py
# def check(user,inLicense, nrepos, **kwargs):
# 
# Path: badges/req.py

# 
# Path: stats/models.py
# class APIStats(models.Model):
#     """
#         API Usage stats.
#         Number of GitHub API Calls each day
#     """
#     date = models.DateField(verbose_name=_('Day stats'))
#     calls_number = models.IntegerField(verbose_name=_('Number of API Calls'), default=0)
# 
#     def inc_call(self):
#         self.calls_number += 1
# 
#     def inc_multiple(self, number):
#         self.calls += number
# 
#     def __unicode__(self):
#         return 'API Stats of {}'.format(self.date)
# 
# Path: skills/models.py
# class Skill(models.Model):
#     """
#         Each developer will have a maximum of top 5 Skills.
#         Each skill is a different Programming Language. With this, we can
#         have information about most well known languages of each developer
# 
#         Skill will be an Inline ForeignKey relationship with Profile
# 
#         Developer 1..1 Profile 1..n Skills (up to 5)
# 
#         Percentage % will be relative. Top language will be 100% and the rest 4
#         will be calculated based on that max
#     """
#     profile = models.ForeignKey('developers.Profile', related_name='skill', blank=False, null=False)
#     language = models.CharField(max_length=255, blank=True, null=True)
#     bytes = models.IntegerField(default=0, blank=True, null=True, help_text=_('Total bytes in this language'))
# 
#     def __unicode__(self):
#         return "{} -> {} from: {}".format(self.language, self.bytes, self.profile)


from audioop import alaw2lin
from datetime import time
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.db.models.signals import pre_save
from django.dispatch import receiver
from django.utils.translation import ugettext as _
from django.db import models
from django.contrib.auth import get_user_model
from badges.models import Badge
from stats.models import APIStats, UserStats
from badges.tasks import Language, Fidelity, Fork, License
from image_cropping import ImageRatioField
from GitGaming.SECRET import GITHUB1, GITHUB2
from badges.req import req
from stats.models import APIStats
from skills.models import Skill
        from worker.tasks import update_developer
import time
import requests
            Update Developer Profile and add achievement for a given badge
        """
        a = Achievement()
        a.user = self
        a.badge = badge
        a.save()

        try:
            self.experience
        except:
            self.experience = 0.0

        given_exp = (float(self.experience) + float(badge.experience))

        if given_exp > 100:
            self.level += 1
            self.experience = (given_exp - 100)
        else:
            self.experience = given_exp

        # Update points
        self.points = (self.level * 100) + self.experience
        self.save()

    def check_badges(self):
        """
            With this function, we check over all the badges still not given to a user. If the Developer
            has the
        """


# Path: badges/models.py
# class Badge(models.Model):
#     """ Parent class
#         Base Badge.
#     """
#     name = models.CharField(blank=False, null=False, max_length=255)
#     title = models.CharField(verbose_name=_('Title given with badge (if proceed)'), blank=True,
#                              null=True, max_length=255)
#     description = models.TextField(blank=False, null=False)
#     image = models.ImageField(upload_to='badges', blank=False, null=False)
#     date = models.DateTimeField(verbose_name='Creation date', name="date", auto_now=True)
#     experience = models.DecimalField(verbose_name=_('Experience gained with this badge'),
#                                      default=5.0, decimal_places=2, max_digits=4)
# 
#     def __unicode__(self):
#         return "{}".format(self.name)
# 
#     @property
#     def is_language(self):
#         try:
#             return self.languagebadge
#         except LanguageBadge.DoesNotExist:
#             return False
# 
#     @property
#     def is_fidelity(self):
#         try:
#             return self.fidelitybadge
#         except FidelityBadge.DoesNotExist:
#             return False
# 
#     @property
#     def is_fork(self):
#         try:
#             return self.forkbadge
#         except ForkBadge.DoesNotExist:
#             return False
# 
#     @property
#     def is_license(self):
#         try:
#             return self.licensebadge
#         except LicenseBadge.DoesNotExist:
#             return False
# 
# Path: stats/models.py
# class APIStats(models.Model):
#     """
#         API Usage stats.
#         Number of GitHub API Calls each day
#     """
#     date = models.DateField(verbose_name=_('Day stats'))
#     calls_number = models.IntegerField(verbose_name=_('Number of API Calls'), default=0)
# 
#     def inc_call(self):
#         self.calls_number += 1
# 
#     def inc_multiple(self, number):
#         self.calls += number
# 
#     def __unicode__(self):
#         return 'API Stats of {}'.format(self.date)
# 
# class UserStats(models.Model):
#     """
#         User Stats.
#         Number of New Users each day
#     """
#     date = models.DateField(verbose_name=_('Day stats'))
#     users = models.IntegerField(verbose_name=_("Number of New Users"), default=0)
# 
#     def inc_user(self):
#         self.users += 1
# 
#     def inc_multiple(self, number):
#         self.calls += number
# 
#     def __unicode__(self):
#         return 'User Stats of {}'.format(self.date)
# 
# Path: badges/tasks/Language.py
# def check(user, bytes, language, **kwargs):
# 
# Path: badges/tasks/Fidelity.py
# def check(date, **kwargs):
# 
# Path: badges/tasks/Fork.py
# def check(user, forks, **kwargs):
# 
# Path: badges/tasks/License.py
# def check(user,inLicense, nrepos, **kwargs):
# 
# Path: badges/req.py

# 
# Path: stats/models.py
# class APIStats(models.Model):
#     """
#         API Usage stats.
#         Number of GitHub API Calls each day
#     """
#     date = models.DateField(verbose_name=_('Day stats'))
#     calls_number = models.IntegerField(verbose_name=_('Number of API Calls'), default=0)
# 
#     def inc_call(self):
#         self.calls_number += 1
# 
#     def inc_multiple(self, number):
#         self.calls += number
# 
#     def __unicode__(self):
#         return 'API Stats of {}'.format(self.date)
# 
# Path: skills/models.py
# class Skill(models.Model):
#     """
#         Each developer will have a maximum of top 5 Skills.
#         Each skill is a different Programming Language. With this, we can
#         have information about most well known languages of each developer
# 
#         Skill will be an Inline ForeignKey relationship with Profile
# 
#         Developer 1..1 Profile 1..n Skills (up to 5)
# 
#         Percentage % will be relative. Top language will be 100% and the rest 4
#         will be calculated based on that max
#     """
#     profile = models.ForeignKey('developers.Profile', related_name='skill', blank=False, null=False)
#     language = models.CharField(max_length=255, blank=True, null=True)
#     bytes = models.IntegerField(default=0, blank=True, null=True, help_text=_('Total bytes in this language'))
# 
#     def __unicode__(self):
#         return "{} -> {} from: {}".format(self.language, self.bytes, self.profile)


# Path: developers/models.py
from audioop import alaw2lin
from datetime import time
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.db.models.signals import pre_save
from django.dispatch import receiver
from django.utils.translation import ugettext as _
from django.db import models
from django.contrib.auth import get_user_model
from badges.models import Badge
from stats.models import APIStats, UserStats
from badges.tasks import Language, Fidelity, Fork, License
from image_cropping import ImageRatioField
from GitGaming.SECRET import GITHUB1, GITHUB2
from badges.req import req
from stats.models import APIStats
from skills.models import Skill
        from worker.tasks import update_developer
import time
import requests

            Update Developer Profile and add achievement for a given badge
        """
        a = Achievement()
        a.user = self
        a.badge = badge
        a.save()

        try:
            self.experience
        except:
            self.experience = 0.0

        given_exp = (float(self.experience) + float(badge.experience))

        if given_exp > 100:
            self.level += 1
            self.experience = (given_exp - 100)
        else:
            self.experience = given_exp

        # Update points
        self.points = (self.level * 100) + self.experience
        self.save()

    def check_badges(self):
        """
            With this function, we check over all the badges still not given to a user. If the Developer
            has the
        """


        for badge in Badge.objects.all():