示例#1
0
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')
示例#2
0
	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))
示例#3
0
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')
示例#4
0
	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)
示例#5
0
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
示例#6
0
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