<s> import datetime <EOL> import os <EOL> import random <EOL> from colorsys import hsv_to_rgb <EOL> from django . db import models <EOL> from django . contrib . auth . models import User <EOL> from settings import GREEN_SCORE , RED_SCORE , UNCERTAIN_SCORE , UNHAPPY_SCORE <EOL> from settings import MEDIA_URL , MAX_SCORE_MINUTES <EOL> from dashboard . util import url_pathify_safe <EOL> from Repository import Repository <EOL> from Blog import Blog <EOL> from URLPathedModel import URLPathedModel <EOL> random . seed ( ) <EOL> class Project ( URLPathedModel ) : <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> title = models . CharField ( max_length = <NUM_LIT:200> ) <EOL> description = models . TextField ( ) <EOL> website = models . URLField ( max_length = <NUM_LIT:200> ) <EOL> repository = models . OneToOneField ( Repository ) <EOL> blog = models . OneToOneField ( Blog ) <EOL> wiki = models . URLField ( max_length = <NUM_LIT:200> ) <EOL> authors = models . ManyToManyField ( User ) <EOL> active = models . BooleanField ( "<STR_LIT>" ) <EOL> score = models . IntegerField ( blank = True , null = True ) <EOL> presentations = models . IntegerField ( default = <NUM_LIT:0> ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> self . title = self . title [ <NUM_LIT:0> : <NUM_LIT:200> ] <EOL> self . website = self . website [ <NUM_LIT:0> : <NUM_LIT:200> ] <EOL> self . wiki = self . wiki [ <NUM_LIT:0> : <NUM_LIT:200> ] <EOL> super ( Project , self ) . save ( * args , ** kwargs ) <EOL> def fetch ( self ) : <EOL> self . blog . fetch ( ) <EOL> self . repository . fetch ( ) <EOL> self . calculate_score ( ) <EOL> def calculate_score ( self ) : <EOL> now = datetime . datetime . utcnow ( ) <EOL> if self . repository . most_recent_date != datetime . datetime ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) : <EOL> td = ( now - self . repository . most_recent_date ) <EOL> r = ( td . seconds + td . days * <NUM_LIT> * <NUM_LIT> ) / <NUM_LIT> <EOL> else : <EOL> r = MAX_SCORE_MINUTES <EOL> r = min ( [ r , MAX_SCORE_MINUTES ] ) <EOL> if self . blog . most_recent_date != datetime . datetime ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) : <EOL> td = ( now - self . blog . most_recent_date ) <EOL> b = ( td . seconds + td . days * <NUM_LIT> * <NUM_LIT> ) / <NUM_LIT> <EOL> else : <EOL> b = MAX_SCORE_MINUTES <EOL> b = min ( [ b , MAX_SCORE_MINUTES ] ) <EOL> self . score = r * <NUM_LIT> + b <EOL> self . save ( ) <EOL> def __unicode__ ( self ) : <EOL> return self . title <EOL> def score_emblem_face ( self ) : <EOL> if self . score < UNCERTAIN_SCORE : <EOL> return os . path . join ( MEDIA_URL , "<STR_LIT>" , "<STR_LIT>" ) <EOL> elif self . score < UNHAPPY_SCORE : <EOL> return os . path . join ( MEDIA_URL , "<STR_LIT>" , "<STR_LIT>" ) <EOL> return os . path . join ( MEDIA_URL , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def score_emblem_css ( self ) : <EOL> hue = min ( [ <NUM_LIT:1> , max ( <NUM_LIT:0> , float ( self . score - GREEN_SCORE ) / <EOL> ( RED_SCORE - GREEN_SCORE ) ) ] ) <EOL> mainbg = hsv_to_rgb ( <NUM_LIT> - hue * <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> lightbg = hsv_to_rgb ( <NUM_LIT> - hue * <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> return """<STR_LIT>""" . format ( int ( mainbg [ <NUM_LIT:0> ] * <NUM_LIT:255> ) , <EOL> int ( mainbg [ <NUM_LIT:1> ] * <NUM_LIT:255> ) , <EOL> int ( mainbg [ <NUM_LIT:2> ] * <NUM_LIT:255> ) , <EOL> int ( lightbg [ <NUM_LIT:0> ] * <NUM_LIT:255> ) , <EOL> int ( lightbg [ <NUM_LIT:1> ] * <NUM_LIT:255> ) , <EOL> int ( lightbg [ <NUM_LIT:2> ] * <NUM_LIT:255> ) ) <EOL> def random_main_page_screenshot ( self ) : <EOL> from Screenshot import Screenshot <EOL> screens = Screenshot . objects . filter ( project = self ) <EOL> if len ( screens ) is <NUM_LIT:0> : <EOL> return None <EOL> return screens [ random . randint ( <NUM_LIT:0> , len ( screens ) - <NUM_LIT:1> ) ] . main_page_url ( ) </s>
