<s> from __future__ import print_function , unicode_literals <EOL> import os , glob <EOL> from weblab . admin . bot . misc import show_time , flush <EOL> import cPickle as pickle <EOL> FILE_NAME_TEMPLATE = "<STR_LIT>" + os . sep + "<STR_LIT>" <EOL> FILL_NUMBER = <NUM_LIT:2> <EOL> RANGES = [ <EOL> lambda : xrange ( <NUM_LIT:1> , <NUM_LIT:5> ) , <EOL> lambda : xrange ( <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:5> ) <EOL> ] <EOL> def get_raw_information ( date , verbose = True ) : <EOL> file_name = FILE_NAME_TEMPLATE % ( date , '<STR_LIT:%s>' ) <EOL> raw_information_filename = '<STR_LIT>' % date <EOL> if os . path . exists ( raw_information_filename ) : <EOL> if verbose : <EOL> print ( "<STR_LIT>" , show_time ( ) ) <EOL> flush ( ) <EOL> raw_information = pickle . load ( open ( raw_information_filename ) ) <EOL> if verbose : <EOL> print ( "<STR_LIT>" , show_time ( ) ) <EOL> flush ( ) <EOL> return raw_information <EOL> if verbose : <EOL> print ( "<STR_LIT>" , show_time ( ) ) <EOL> flush ( ) <EOL> def calculate_positions ( initial ) : <EOL> data = { } <EOL> for r in RANGES : <EOL> for i in r ( ) : <EOL> data [ i ] = str ( initial ) . zfill ( FILL_NUMBER ) <EOL> initial += <NUM_LIT:1> <EOL> return data , initial <EOL> def calculate_protocols ( ) : <EOL> protocols = { <EOL> "<STR_LIT>" : { } , <EOL> } <EOL> protocols = { } <EOL> data , initial = calculate_positions ( <NUM_LIT:0> ) <EOL> protocols [ "<STR_LIT>" ] = data <EOL> return protocols <EOL> protocols = calculate_protocols ( ) <EOL> def get_results ( protocol , number ) : <EOL> found_resources = sorted ( glob . glob ( file_name % "<STR_LIT:*>" ) , lambda x , y : len ( x ) - len ( y ) ) <EOL> if len ( found_resources ) == <NUM_LIT:0> : <EOL> raise Exception ( "<STR_LIT>" % file_name ) <EOL> regular_length = len ( found_resources [ len ( found_resources ) / <NUM_LIT:2> ] ) <EOL> number_length = regular_length - len ( file_name % '<STR_LIT>' ) <EOL> filename = file_name % str ( int ( protocols [ protocol ] [ number ] ) ) . zfill ( number_length ) <EOL> results = pickle . load ( open ( filename ) ) <EOL> return results <EOL> def generate_data ( protocol ) : <EOL> x = [ ] <EOL> y = [ ] <EOL> for r in RANGES : <EOL> for n in r ( ) : <EOL> x . append ( n ) <EOL> results = get_results ( protocol , n ) <EOL> y . append ( results ) <EOL> return x , y <EOL> raw_information = { } <EOL> for protocol in protocols . keys ( ) : <EOL> x , y = generate_data ( protocol ) <EOL> raw_information [ protocol ] = ( x , y ) <EOL> pickle . dump ( raw_information , open ( raw_information_filename , '<STR_LIT:w>' ) ) <EOL> if verbose : <EOL> print ( "<STR_LIT>" , show_time ( ) ) <EOL> flush ( ) <EOL> return raw_information </s>
