Skip to content

Commit

Permalink
Merge pull request #61 from gisce/IMP_longitud_with_3_decimals
Browse files Browse the repository at this point in the history
IMP longitud with 3 decimals, PEP8ing
  • Loading branch information
tinogis committed Jun 2, 2015
2 parents 682fbbe + 75edaa8 commit 6c5be7d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
17 changes: 9 additions & 8 deletions libcnmc/res_4771/LAT.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ def consumer(self):
ids = O.GiscedataAtTram.search(
search_params, 0, 0, False, {'active_test': False})
for tram in O.GiscedataAtTram.read(ids, fields_to_read):
#Comprovar el tipus del cable
# Comprovar el tipus del cable
cable = O.GiscedataAtCables.read(tram['cable'][0],
['tipus'])
tipus = O.GiscedataAtTipuscable.read(cable['tipus'][0],
['codi'])
#Si el tram tram es embarrat no l'afegim
# Si el tram tram es embarrat no l'afegim
if tipus['codi'] == 'E':
continue

Expand All @@ -86,7 +86,8 @@ def consumer(self):

comunitat = ''
if linia['municipi']:
id_comunitat = O.ResComunitat_autonoma.get_ccaa_from_municipi(
ccaa_obj = O.ResComunitat_autonoma
id_comunitat = ccaa_obj.get_ccaa_from_municipi(
linia['municipi'][0])
comunidad = O.ResComunitat_autonoma.read(id_comunitat,
['codi'])
Expand All @@ -110,6 +111,9 @@ def consumer(self):
origen = tallar_text(tram['origen'], 50)
final = tallar_text(tram['final'], 50)

longitud = round(tram['longitud_cad'] * coeficient
/ 1000.0, 3) or 0.001

output = [
'A%s' % tram['name'],
tram['cini'] or '',
Expand All @@ -123,10 +127,7 @@ def consumer(self):
tram['circuits'] or 1,
1,
format_f(tensio),
format_f(
round(tram['longitud_cad'] * coeficient / 1000.0,
3)
or 0),
format_f(longitud, 3),
format_f(cable['intensitat_admisible']),
format_f(cable['seccio']),
capacitat,
Expand All @@ -140,4 +141,4 @@ def consumer(self):
if self.raven:
self.raven.captureException()
finally:
self.input_q.task_done()
self.input_q.task_done()
8 changes: 5 additions & 3 deletions libcnmc/res_4771/LBT.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def consumer(self):
count += 1
item = self.input_q.get()
self.progress_q.put(item)

linia = O.GiscedataBtElement.read(item, fields_to_read)

res = O.GiscegisEdge.search([('id_linktemplate', '=',
Expand Down Expand Up @@ -126,6 +126,9 @@ def consumer(self):
origen = tallar_text(edge['start_node'][1], 50)
final = tallar_text(edge['end_node'][1], 50)

longitud = round(linia['longitud_cad'] * coeficient / 1000.0,
3) or 0.001

output = [
'B%s' % linia['name'],
linia['cini'] or '',
Expand All @@ -139,8 +142,7 @@ def consumer(self):
1,
1,
format_f(tensio),
format_f(round(linia['longitud_cad']
* coeficient / 1000.0, 3) or 0),
format_f(longitud, 3),
format_f(intensitat),
format_f(cable['seccio']),
format_f(capacitat),
Expand Down
7 changes: 5 additions & 2 deletions libcnmc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def get_id_expedient(connection, expedients_id):
id_expedient = id_expedients[0]
return id_expedient


def get_id_municipi_from_company(connection):
O = connection
id_municipi = False
Expand All @@ -77,6 +78,8 @@ def tallar_text(text, long):
else:
return text

def format_f(num):

def format_f(num, decimals=2):
'''formats float with comma decimal separator'''
return ('%.2f' % num).replace('.', ',')
fstring = '%%.%df' % decimals
return (fstring % num).replace('.', ',')

0 comments on commit 6c5be7d

Please sign in to comment.