def __init__(self, file_): self.dati = SchemaXls(file_) self.ncol = self.dati.ncol - 1 self.nrow = self.dati.nrow - 1 self.tab_pesi = np.array([0 for i in xrange(self.nrow * self.ncol) ]).reshape((self.ncol, self.nrow)) self.day = range(self.ncol) self.hour = range(self.nrow) self.day_nome = {} for k, v in self.dati.schema.items(): if k == None or k == '': continue self.day_nome[k] = v - 1 self.hour_nome = {} i = 0 for r in self.dati.get_rows_list(): date = xldate_as_tuple(r[0].value, 0) ora = '{:02d}:{:02d}'.format(date[3], date[4]) self.hour_nome[ora] = i i = i + 1 for i in self.day: for j in self.hour: self.tab_pesi[i, j] = self.dati.sheet.cell(j + 1, i + 1).value
def __init__(self, C, CIC, file_edi, file_corsi, map_corsi): self.edi = SchemaXls(file_edi) self.corsi = SchemaXls(file_corsi) self.map_corsi = map_corsi self.n_c = len(C) self.n_e = len(Sede.map_sedi) self.corsi_edi = np.array([0 for i in xrange(self.n_c * self.n_e) ]).reshape((self.n_c, self.n_e)) CIC_union = [c for C_ in CIC for c in C_] for c in CIC_union: l = self.get_cod(c) e = self.get_e(l) self.corsi_edi[c, e] = 1
class SchemaEdi: def __init__(self, C, CIC, file_edi, file_corsi, map_corsi): self.edi = SchemaXls(file_edi) self.corsi = SchemaXls(file_corsi) self.map_corsi = map_corsi self.n_c = len(C) self.n_e = len(Sede.map_sedi) self.corsi_edi = np.array([0 for i in xrange(self.n_c * self.n_e) ]).reshape((self.n_c, self.n_e)) CIC_union = [c for C_ in CIC for c in C_] for c in CIC_union: l = self.get_cod(c) e = self.get_e(l) self.corsi_edi[c, e] = 1 def get_corsi_edi(self): return self.corsi_edi def get_cod(self, c): l = self.map_corsi[c]['corsi effettivi'][0]['corso_di_laurea'] return l def get_e(self, l): e = self.edi.get_campo_where('Edificio', **{'Corso di laurea': l}) return Sede.get_sede(e).n
class SchemaDisp: def __init__(self, file_, map_corsi, meta): self.dati = SchemaXls(file_) self.map = map_corsi self.meta = meta self.rows = self.dati.get_rows_list_schema() self.lista_disp = [] self.dict_disp = {} for r in self.rows: corsi = self.get_corsi_prof(r['PROF']) d = self.get_n_giorno(r['GIORNO']) lista_h = self.get_n_ora(r['DALLE'], r['ALLE']) self.aggiungi_dict(r['PROF'], d, lista_h) for c in corsi: for h in lista_h: tupla = (c, d, h) self.lista_disp.append(tupla) def aggiungi_dict(self, prof, giorno, lista_h): if not self.dict_disp.has_key(prof): self.dict_disp[prof] = [] item_prof = self.dict_disp[prof] item_g = None for g in item_prof: if g.haskey(giorno): item_g = g[giorno] if item_g != None: item_g[giorno] = item_g[giorno] + lista_h else: item_g = {giorno: lista_h} item_prof.append(item_g) def get_dict_disp(self): return self.dict_disp def get_prof_out(self): return self.lista_disp def get_corsi_prof(self, prof): res = [] for k, v in self.map.items(): if v['prof'] == prof: res.append(k) return res def get_n_giorno(self, giorno): return self.meta['giorni'][giorno] def get_n_ora(self, dalle_, alle_): dalle = xldate_as_tuple(dalle_, 0) dalle = '{:02d}:{:02d}'.format(dalle[3], dalle[4]) alle = xldate_as_tuple(alle_, 0) alle = '{:02d}:{:02d}'.format(alle[3], alle[4]) inizio = self.meta['ore'][dalle] fine = self.meta['ore'][alle] return range(inizio, fine)
def __init__(self, file_): self.dati = SchemaXls(file_) self.aule = [] aule = self.dati.get_rows_list_schema() for a in aule: att = {} for k, v in a.items(): if k == 'NOME' or k == 'SEDE' or k == 'CAPIENZA': continue if v.upper() == 'SI': att[k] = v item = Aula(a['NOME'], a['SEDE'], a['CAPIENZA'], att) self.aule.append(item)
def __init__(self, file_, map_corsi, meta): self.dati = SchemaXls(file_) self.map = map_corsi self.meta = meta self.rows = self.dati.get_rows_list_schema() self.lista_disp = [] self.dict_disp = {} for r in self.rows: corsi = self.get_corsi_prof(r['PROF']) d = self.get_n_giorno(r['GIORNO']) lista_h = self.get_n_ora(r['DALLE'], r['ALLE']) self.aggiungi_dict(r['PROF'], d, lista_h) for c in corsi: for h in lista_h: tupla = (c, d, h) self.lista_disp.append(tupla)
def __init__(self, file_, meta): self.dati = SchemaXls(file_) self.meta = meta self.semestre = int( self.dati.get_campo_where('Valore', Parametro='semestre')) self.pranzo = self.dati.get_campo_where( 'Valore', Parametro='ora fine pausa pranzo') self.cap = self.dati.get_campo_where('Valore', Parametro='valore capienza aule') self.att = self.dati.get_campo_where('Valore', Parametro='valore attrezzature') self.sov = self.dati.get_campo_where( 'Valore', Parametro='valore sovrapposizione corsi') self.edi = self.dati.get_campo_where('Valore', Parametro='valore edifici') self.comp = self.dati.get_campo_where( 'Valore', Parametro='valore compattezza orario')
class SchemaAule: def __init__(self, file_): self.dati = SchemaXls(file_) self.aule = [] aule = self.dati.get_rows_list_schema() for a in aule: att = {} for k, v in a.items(): if k == 'NOME' or k == 'SEDE' or k == 'CAPIENZA': continue if v.upper() == 'SI': att[k] = v item = Aula(a['NOME'], a['SEDE'], a['CAPIENZA'], att) self.aule.append(item) def get_lista_aule(self): res = [] for a in self.aule: res.append(a.n) return res def get_aule_from_index(self, i): for a in self.aule: if a.n == i: return a def get_mat_sedi(self): n_s = len(Sede.map_sedi) n_a = Aula.index res = np.array([0 for i in xrange(n_a * n_s)]).reshape((n_a, n_s)) lista = self.get_lista_aule() for i in lista: a = self.get_aule_from_index(i) s = a.sede.n res[i, s] = 1 return res def get_matrix_att(self): n_att = len(Aula.map_att) n_aule = Aula.index res = np.array([0 for i in xrange(n_att * n_aule)]).reshape( (n_aule, n_att)) lista = self.get_lista_aule() for i in lista: a = self.get_aule_from_index(i) l_att = a.list_att for j in l_att: res[i, j] = 1 return res def get_set_att(self): return set(range(len(Aula.map_att))) def get_set_sedi(self): return set(range(len(Sede.map_sedi)))
class SchemaParametri: def __init__(self, file_, meta): self.dati = SchemaXls(file_) self.meta = meta self.semestre = int( self.dati.get_campo_where('Valore', Parametro='semestre')) self.pranzo = self.dati.get_campo_where( 'Valore', Parametro='ora fine pausa pranzo') self.cap = self.dati.get_campo_where('Valore', Parametro='valore capienza aule') self.att = self.dati.get_campo_where('Valore', Parametro='valore attrezzature') self.sov = self.dati.get_campo_where( 'Valore', Parametro='valore sovrapposizione corsi') self.edi = self.dati.get_campo_where('Valore', Parametro='valore edifici') self.comp = self.dati.get_campo_where( 'Valore', Parametro='valore compattezza orario') def get_hi(self): ora = xldate_as_tuple(self.pranzo, 0) o = self.meta['ore']['{:02d}:{:02d}'.format(ora[3], ora[4])] return [0, o] def get_g_out(self, g): if 'S' in self.dati.get_campo_where( 'Valore', Parametro='compattare orario').upper(): return [g[0], g[-1]] return [] def get_max_time(self): max_time = self.dati.get_campo_where('Valore', Parametro='tempo massimo') if max_time > 0: return max_time return 0
def __init__(self, C, schema_aule, file_, dict_): self.dati = SchemaXls(file_) self.schema = dict( (k.upper(), v) for k, v in self.dati.schema.iteritems()) self.dict = dict_ self.n_c = len(C) self.n_att = len(schema_aule.get_set_att()) self.corsi_att = np.array([0 for i in xrange(self.n_att * self.n_c) ]).reshape((self.n_c, self.n_att)) self.list_att = Aula.map_att.keys() self.list_col_att = dict( (a, self.schema[a] - 2) for a in self.list_att) for k, block_list in self.dict.items(): for block in block_list: for att in self.list_att: c = block['index'] t = Aula.get_n_att(att) if 'S' in block['att'][self.list_col_att[att]].upper(): self.corsi_att[c, t] = 1