class App(object): def __init__(self): self.config = IniParser() self._lastTick = 0 self.deltaTime = 0 try: self.config.read(open('config.cfg')) except: self.config.data['DISPLAY'] = { 'fullscreen': 'false', 'nativemode': 'false', 'opengl': 'false' } self.config.data['PATHS'] = { 'gamelist': './gamelist.csv', 'favorites': './fav.csv', 'sdcard': '.' } self.config.write(open('config.cfg', 'w')) pygame.init() self.input = Input() self.game = Game(self) #end of init def run(self): self.game.start() # start game self.game.active = True self._lastTick = pygame.time.get_ticks() while 1: # main game loop # deltaTime in seconds. t = pygame.time.get_ticks() self.deltaTime = (t - self._lastTick) / 1000.0 self._lastTick = t for event in pygame.event.get(): self.input.collectEvents(event) if event.type == pygame.QUIT: self.game.active = False sys.exit(0) self.game.update(self.deltaTime) self.game.render() #end of run #end of App
def getContent(self, fileName): parser = IniParser() dict = parser.read(fileName) sdk_config = dict['opensdk'] sdk_config['checkResult'] = True sdk_config['debugInfo'] = [] sdk_config['url'] = r'https://' + \ sdk_config['host'] + r':' + sdk_config['port'] self.checkParameter(sdk_config) return dict
def generate_versions(f, plants): v = IniParser() v.read('versions.ini') for app in v.sections(): f.write('<tr>\n') f.write('<th>%s</th>\n' % app) for i in plants: tooltip = ' title = \'%s%s\'' % (app, create_tooltip(i)) o = ('', '') if app in i.versions: o = i.versions[app] ver = o[0] hash = o[1] current = v.get(app, 'current').split(',' ' ') testing = v.get(app, 'testing').split(',' ' ') if ver in current: style = ' class="green"' elif ver in testing: style = ' class="yellow"' else: style = ' class="pink"' #endif if hash != v.get(app, 'v%s' % ver): style = ' class="red"' if not hash and not ver: style = ' class="grey"' f.write('<td%s%s>%s</td>\n' % (tooltip, style, ver)) #endfor f.write('</tr>\n')
def __init__(self): self.config = IniParser() self._lastTick = 0 self.deltaTime = 0 try: self.config.read(open('config.cfg')) except: self.config.data['DISPLAY'] = { 'fullscreen': 'false', 'nativemode': 'false', 'opengl': 'false' } self.config.data['PATHS'] = { 'gamelist': './gamelist.csv', 'favorites': './fav.csv', 'sdcard': '.' } self.config.write(open('config.cfg', 'w')) pygame.init() self.input = Input() self.game = Game(self)
def assign_materials_to_silos(adaptivity): log.info('assign_materials_to_silos function called') pom = {'AGG': 'Aggregate', 'CEM': 'Cement', 'ADM': 'Admixture', 'WTR': 'Water'} ret = {} f = './temp/ini/placemnt.ini' if not os.path.isfile(f): return ret i = IniParser() i.read(f) for silo in adaptivity: base = silo[0:3] number = silo[3:] for s in i.sections(): if pom[base] in s and 'Silo%s' % number in s: ret[silo] = i.get(s, 'Name') #endif #endfor #endfor return ret
def generate_ini_hashes(f, plants): h = IniParser() h.read('hashes.ini') for ini in h.sections(): f.write('<tr>\n') f.write('<th>%s</th>\n' % ini) for i in plants: tooltip = ' title = \'%s%s\'' % (ini, create_tooltip(i)) if ini in i.ini_hashes: hash = 'h%s' % i.ini_hashes[ini] style = ' class="pink"' if h.has_option(ini, hash): val = h.get(ini, hash) app = val.split(':')[0] if (h.get(ini, hash) == '' or (app in i.versions and i.versions[app][0] in h.get(ini, hash))) \ and (not h.has_option(ini, '%s_motherboard' % hash) or i.motherboard in h.get(ini, '%s_motherboard' % hash)): style = ' class="green"' if h.has_option(ini, '%s_message' % hash): hash = h.get(ini, '%s_message' % hash) else: hash = '' else: style = ' class="yellow"' #endif #endif else: hash = '' style = ' class="grey"' #endif f.write('<td%s%s>%s</td>\n' % (tooltip, style, hash)) #endfor f.write('</tr>\n')
def get_structure(self): log.log('get_structure function called') self.structure = [] f = './temp/ini/parameters.ini' if not os.path.isfile(f): return i = IniParser() i.read(f) self.structure.append(('mixer', i.get('Mixer', 'Volume'))) f = './temp/ini/base.ini' if not os.path.isfile(f): return i = IniParser() i.read(f) if i.getint('General', 'WeighingConveyer') > 0: self.structure.append(('weighing conv', i.getint('General', 'WeighingConveyer'))) if i.getint('Structure', 'Lifts') > 0: self.structure.append(('lifts', i.getint('Structure', 'Lifts'))) if i.getint('Structure', 'Conveyers') > 0: self.structure.append(('convs', i.getint('Structure', 'Conveyers'))) if i.getint('Structure', 'Reservoirs') > 0: self.structure.append(('reservoirs', i.getint('Structure', 'Reservoirs'))) for sec in ('Aggregate_Bin', 'Cement_Bin', 'Water_Bin', 'Admixture_Bin'): silos = 0 #goes through up to 10 possible bins for num in range(1, 10): pom = i.getint('%s%i' % (sec, num), 'Silos', 0) if pom > silos: silos = pom #endfor abr = sec.split('_')[0] self.structure.append(('%s' % abr.lower(), '%i -> %i -> %i' % (silos, i.getint(abr, 'Bins'), i.getint(abr, 'Scales')))) #endfor x = i.get('BinaryInput_Signals', 'I_Bin1CEMclosed', 'x').strip() if not x in ('x', '255'): self.structure.append(('cement_bin1 limit switch signal', x)) x = i.get('BinaryInput_Signals', 'I_Bin2CEMclosed', 'x').strip() if not x in ('x', '255'): self.structure.append(('cement_bin2 limit switch signal', x)) if i.getint('Hardware', 'IND-1') > 2: self.structure.append(('hardware', 'old')) else: self.structure.append(('hardware', 'new')) x = i.get('Hardware', 'PointerCounts', 'x').strip() self.structure.append(('pointercounts', x))
def get_coefficients(self): log.log('get_coefficients function called') self.coefficients = {} converter = 8192 if self.mj in ('mj04', 'mj22', 'mj36'): converter = 4096 l = [] f = './temp/ini/base.ini' if not os.path.isfile(f): return i = IniParser() i.read(f) for s in i.options('AnalogInput_Signals'): if 'scale' in s.lower() and i.get('AnalogInput_Signals', s) != 'x': l.append((s, i.getint('AnalogInput_Signals', s))) #endfor f = './temp/ini/parameters.ini' if not os.path.isfile(f): return i = IniParser() i.read(f) for s, a in l: self.coefficients[s] = i.getfloat(s, 'Range') #endfor f = './temp/ini/settings.ini' if not os.path.isfile(f): return i = IniParser() i.read(f) for s, a in l: print s, a print self.coefficients[s] print i.getfloat('AnalogInput_Coefficients', 'Coefficient%i' % a) print type(self.coefficients[s]) print type(i.getfloat('AnalogInput_Coefficients', 'Coefficient%i' % a)) capacity = self.coefficients[s] difference = (i.getfloat('AnalogInput_Coefficients', 'Coefficient%i' % a) / (capacity/converter) - 1) * 100 offset = i.getint('AnalogInput_Offsets', 'Offset%i' % a) self.coefficients[s] = (capacity, difference, offset)
def get_little_amounts(self): log.info('little amounts function called') silo = {} self.little_amounts_fails = {} doba = None vaha = None navazeno = None analog = None adaptivita = None pozadavek = None zasobnik = 99 # can delete this line after three month (bacuse of error in info txt from Piestany) fn = 'control.log' for l in give_lines(fn, 3): if 'poddavkovani ' in l.lower(): zasobnik = int(l.split()[-1]) vaha = None navazeno = None pozadavek = None elif 'dobaotevreni ' in l.lower(): pom = float(l.split()[-1]) if pom > 3 or pom < 0: continue # filtrace demetskych hodnot v milisekundach a zapornych hodnot doba = pom elif 'mezistav1 ' in l.lower(): vaha = float(l.split()[-1]) elif 'NejblizsiCil2' in l and vaha: pozadavek = float(l.split()[-1]) - vaha elif 'PrumernaHodnotaAI[CisloAnalogu] - VychoziVaha' in l: analog = float(l.split()[-1]) elif 'frakcenamereno2 ' in l.lower() and vaha: navazeno = float(l.split()[-1]) - vaha #endif if doba and navazeno: log.info('%i, %0.2f, %i' % (navazeno, doba, zasobnik)) if navazeno < 30 or navazeno > 500: log.info('little amount fail: %i, %0.2f, %i' % (navazeno, doba, zasobnik)) if not zasobnik in self.little_amounts_fails: self.little_amounts_fails[zasobnik] = [] #endif self.little_amounts_fails[zasobnik].append('%i, %0.2f' % (navazeno, doba)) doba = None continue #endif if analog: adaptivita = navazeno - analog + vaha if not zasobnik in silo: silo[zasobnik] = [] silo[zasobnik].append((doba, navazeno, pozadavek, adaptivita)) doba = None vaha = None navazeno = None analog = None adaptivita = None #endif #endfor #log.info('%s' % silo) self.silo = {} self.little_amounts_error = False f = './temp/ini/adapt.ini' if not os.path.isfile(f): return adapt = IniParser() adapt.read(f) f = './temp/ini/parameters.ini' if not os.path.isfile(f): return parameters = IniParser() parameters.read(f) for k in silo: self.little_amounts_error = adapt.has_option('Aggregate', 'VelocityOfFilling1-%s' % k) param_velocity = 0 param_offset = 0 if parameters.has_option('Aggregate_Bin1_Silo%s' % k, 'Velocity_Base'): param_velocity = parameters.getint('Aggregate_Bin1_Silo%s' % k, 'Velocity_Base') param_offset = parameters.getfloat('Aggregate_Bin1_Silo%s' % k, 'Additional_Time') else: self.little_amounts_error = True #endif x = 0 sez = {} while x < 1.5: if not x in sez: sez[x] = [] for doba, navazeno, pozadavek, adaptivita in silo[k]: if doba-x == 0: continue #I dont know why sez[x].append(navazeno/(doba - x)) #endfor x = x + 0.01 #endwhile minimum = None for x in sorted(sez): sqr_sum = 0 avg = 0 dev = 0 avg = sum(sez[x]) * 1.0 / len(sez[x]) for velocity in sez[x]: sqr_sum += ((velocity - avg) ** 2) / len(sez[x]) #endfor dev = sqr_sum ** 0.5 if not minimum or dev < minimum: #print dev minimum = dev self.silo[k] = (x, avg, len(sez[x]), dev, param_velocity, param_offset)
def get_adaptivity(mj): log.log('get_adaptivity function called') class Adaptivity(): def __init__(self, silo, scale, coefficient): self.silo = silo #log.info('creating new class for %s' % self.silo) self.scale = scale self.coefficient = coefficient self.first = None #enddef def check_line(self, line): if not self.scale in line: return if not self.first and self.first != 0: self.first = int(line.split('=')[1]) #log.info('%s first %s' % (self.silo, self.first)) else: self.adaptivity = (int(line.split('=')[1]) - self.first) * self.coefficient self.time = get_datetime_from_log(line) return 'all done' #endif #enddef #enclass ret = {} # ret[silo] = [(time, adaptivity), ...] materials = {'AGG': 'Aggregate', 'CEM': 'Cement', 'ADM': 'Admixture', 'WTR': 'Water'} cache = {} # cache[silo] = {'Scale': scale, 'Coefficient': coefficient} incompletes = [] # incompletes = [Adativity(), ...] f = './temp/ini/base.ini' if not os.path.isfile(f): return ret base = IniParser() base.read(f) f = './temp/ini/settings.ini' if not os.path.isfile(f): return ret settings = IniParser() settings.read(f) fn = 'recordedsignals.log' for l in give_lines(fn, 3): for m in materials: if m in l and 'O_' in l and 'intoBin' in l and ')=0' in l: silo = '%s%s' % (m, l.split(m)[1].split('into')[0]) # for example AGG5 if not silo in cache: bin = 'Bin%s' % l.split('intoBin')[1].split(')=')[0] scale = '%s_Scale%s' % (materials[m], base.get('%s_%s' % (materials[m], bin), 'CorrespondingScale')) signal = base.get('AnalogInput_Signals', scale) coefficient = settings.getfloat('AnalogInput_Coefficients', 'Coefficient%s' % signal) cache[silo] = {} cache[silo]['Scale'] = scale cache[silo]['Coefficient'] = coefficient #endif if not silo in ret: ret[silo] = [] # Adding new adaptivities to list incompletes.append(Adaptivity(silo, cache[silo]['Scale'], cache[silo]['Coefficient'])) break #endif #endfor if 'Scale' in l: for i in incompletes: if i.check_line(l): ret[i.silo].append((i.time, i.adaptivity)) incompletes.remove(i) #endif #endfor #endif #endfor # read alternately adaptivity from info.txt fn = 'control.log' materials = {'aggregate': 'AGG', 'cement': 'CEM', 'admixture': 'ADM', 'water': 'WTR'} for l in give_lines(fn, 3): if not 'adaptivity for' in l: continue material_type = materials[l.split(' for ')[1].split(' bin ')[0]] silo_number = l.split(' silo ')[1].split(':')[0] adaptivity = l.split(': ')[-1].strip() time = get_datetime_from_log(l) silo = '%s%s' % (material_type, silo_number) if not silo in ret: ret[silo] = [] ret[silo].append((time, float(adaptivity))) #endfor # create output files for silo in ret: log.info('creating file for silo %s' % silo) a = '../public_html_incoming' if not os.path.isdir(a): a = './public_html_incoming' #endif f = open('%s/%s%s.csv' % (a, mj, silo), 'w') for x,y in ret[silo]: f.write('%s;%i\n' % (x.strftime('%Y-%m-%d %H:%M:%S'), y)) #endfor f.close() #endfor return ret