0

I am trying to make the code below make decisions between two different data sources. Basically, if the data source is m_mas it should go through one set of processes, and if it is m_rma, the coding should go through another set of processes.

I am not sure if I am using the decision making syntax correctly and would appreciate any help. Thanks.

if self.dataSource == "m_mas":
		  if maxSignalInDatasource < 1000:
			# the little graph on the tga image has a scale
			# such that 1 unit is 0.031 pixels for the range 0-1000
			# Also it is displaced to the right by some pixels
			offsetX = maxSignalInDatasource*0.029
			offsetX += (displaceX + 23)
			int(offsetX)
			draw.line((offsetX, top1, offsetX, bottom), fill='#cccccc')
		    elif maxSignalInDatasource > 1000:
			# the little graph on the tga image has a scale
			# such that 1 unit is 0.003222 pixels for the range 1000-10000
			# This bit of the graph is displaced another 31 pixels
			offsetX = maxSignalInDatasource*0.0029
			offsetX += (displaceX + 48)
			int(offsetX)
			draw.line((offsetX, top2, offsetX, bottom), fill='#cccccc')
		      elif viewMaxSignal1 < 1000:
			# the little graph on the tga image has a scale
			# such that 1 unit is 0.031 pixels for the range 0-1000
			# Also it is displaced to the right by some pixels
			offsetX = viewMaxSignal1*0.029
			offsetX += (displaceX + 23)
			int(offsetX)
			draw.line((offsetX, top1, offsetX, bottom), fill=red)
		         elif viewMaxSignal1 > 1000:
			# the little graph on the tga image has a scale
			# such that 1 unit is 0.003222 pixels for the range 1000-10000
			# This bit of the graph is displaced another 31 pixels
			offsetX = viewMaxSignal1*0.0029
			offsetX += (displaceX + 48)
			int(offsetX)
			draw.line((offsetX, top2, offsetX, bottom), fill=red)
		    elif mode == 'Compare':
			if viewMaxSignal2 < 1000:
			    	# the little graph on the tga image has a scale
				# such that 1 unit is 0.031 pixels for the range 0-1000
				# Also it is displaced to the right by some pixels
				offsetX = viewMaxSignal2*.0029
				offsetX += (displaceX + 29)
				int(offsetX)
				draw.line((offsetX, top1, offsetX, bottom), fill=blue)
			    elif viewMaxSignal2 > 1000:
				# the little graph on the tga image has a scale
				# such that 1 unit is 0.003222 pixels for the range 1000-10000
				# This bit of the graph is displaced another 31 pixels
				offsetX = viewMaxSignal2*0.003222
				offsetX += (displaceX + 37)
				int(offsetX)
				draw.line((offsetX, top2, offsetX, bottom), fill=blue)

		else self.dataSource == "m_rma":
		if maxSignalInDatasource < 18:
			# the little graph on the tga image has a scale
			# such that 1 unit is 0.031 pixels for the range 0-1000
			# Also it is displaced to the right by some pixels
			offsetX = maxSignalInDatasource*0.004
			offsetX += (displaceX + 12)
			int(offsetX)
			draw.line((offsetX, top1, offsetX, bottom), fill='#cccccc')
		#if maxSignalInDatasource > 1000:
			# the little graph on the tga image has a scale
			# such that 1 unit is 0.003222 pixels for the range 1000-10000
			# This bit of the graph is displaced another 31 pixels
			#offsetX = maxSignalInDatasource*0.0029
			#offsetX += (displaceX + 48)
			#int(offsetX)
			#draw.line((offsetX, top2, offsetX, bottom), fill='#cccccc')
		if viewMaxSignal1 < 18:
			# the little graph on the tga image has a scale
			# such that 1 unit is 0.031 pixels for the range 0-1000
			# Also it is displaced to the right by some pixels
			offsetX = viewMaxSignal1*0.004
			offsetX += (displaceX + 12)
			int(offsetX)
			draw.line((offsetX, top1, offsetX, bottom), fill=red)
		#if viewMaxSignal1 > 1000:
			# the little graph on the tga image has a scale
			# such that 1 unit is 0.003222 pixels for the range 1000-10000
			# This bit of the graph is displaced another 31 pixels
			#offsetX = viewMaxSignal1*0.0029
			#offsetX += (displaceX + 48)
			#int(offsetX)
			#draw.line((offsetX, top2, offsetX, bottom), fill=red))
		if mode == 'Compare':
			if viewMaxSignal2 < 18:
			    	# the little graph on the tga image has a scale
				# such that 1 unit is 0.031 pixels for the range 0-1000
				# Also it is displaced to the right by some pixels
				offsetX = viewMaxSignal2*.004
				offsetX += (displaceX + 28)
				int(offsetX)
				draw.line((offsetX, top1, offsetX, bottom), fill=blue)
			#if viewMaxSignal2 > 1000:
				# the little graph on the tga image has a scale
				# such that 1 unit is 0.003222 pixels for the range 1000-10000
				# This bit of the graph is displaced another 31 pixels
				#offsetX = viewMaxSignal2*0.003222
				#offsetX += (displaceX + 37)
				#int(offsetX)
				#draw.line((offsetX, top2, offsetX, bottom), fill=blue)
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by woooee
0

First, what happens if maxSignalInDatasource == 1000? I changed the first if to <= 1000. Second, int(offsetX) does nothing, so that was changed to offsetX_int = int(offsetX). Third, the way you have the indents positioned in your post, everything from
elif viewMaxSignal1 < 1000:
and below will only be executed if maxSignalInDatasource == 1000. The first pair of if/elif will catch everything else. You might consider using a function also instead of the redundant code, like the following.

def draw_line(multiplier_1, multiplier_2, displace_add, top_x, fill_x):
    offsetX = multiplier_1 * multipler_2
    offsetX += (displaceX + displace_add)
    offsetX_int = int(offsetX)
    draw.line((offsetX_int, top_x, offsetX_int, bottom), fill=fill_x)


if self.dataSource == "m_mas":
    if maxSignalInDatasource <= 1000:
        draw_line(maxSignalInDatasource, 0.029, 23, top1, '#cccccc'):
    else:   ## all other maxSignalInDatasource values (i.e. > 1000)
        draw_line(maxSignalInDatasource, 0.0029, 48, top2, '#cccccc'):

else self.dataSource == "m_rma":
    if maxSignalInDatasource < 18:
        ETC...
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.