fork download
  1. import sys
  2.  
  3. #Time for gschem unit in ns
  4. XU = 5.0
  5. #Voltage for unit for ch 1 and 2 in mV
  6. YU1 = 0.5
  7. YU2 = 5.0
  8. #Resistors 2 and 3 resistances in ohms
  9. R2 = 983.0
  10. R3 = 99.4
  11. #Frequency in Hz
  12. F = 30303.0
  13.  
  14. def getlist(list, x0, y0, invert):
  15. for i in range(len(list)):
  16. list[ i ][0] -= x0
  17. list[ i ][2] -= x0
  18. if (invert):
  19. list[ i ][1] = y0 - list[ i ][1]
  20. list[ i ][3] = y0 - list[ i ][3]
  21. else:
  22. list[ i ][1] -= y0
  23. list[ i ][3] -= y0
  24. return list
  25.  
  26. def gety(list, i, t):
  27. lx = float(list[ i ][2] - list[ i ][0])
  28. ly = float(list[ i ][3] - list[ i ][1])
  29. dx = float(t - list[ i ][0])
  30. dy = ly * abs(dx / lx)
  31. return list[ i ][1] + dy
  32.  
  33. def output(s, e):
  34. #Energy in uJ
  35. e *= XU / 10 / 1000000
  36. print("%s power was %.3f uW" % (s, F * e))
  37.  
  38. lines = []
  39. for s in sys.stdin:
  40. l = []
  41. i1 = 1
  42. if (s[0] != "L"): continue
  43. for j in range(4):
  44. i0 = i1 + 1
  45. i1 = s.find(" ", i0)
  46. l.append(int(s[i0:i1]))
  47. lines.append(l)
  48.  
  49. x0 = lines[0][0]
  50. y0 = lines[-2][1]
  51. y1 = lines[-1][1]
  52. lines.pop()
  53. lines.pop()
  54. i1 = map(lambda l: l[1] <= y0, lines).index(True)
  55. i2 = map(lambda l: l[0] == x0, lines[1 : ]).index(True) + 1
  56. ilist = getlist(lines[: i1], x0, y0, False)
  57. olist = getlist(lines[i1 : i2], lines[i1][0], y0, True)
  58. r2list = getlist(lines[i2 : ], lines[i2][0], y1, False)
  59.  
  60. e = 0.0
  61. i1 = i2 = 0
  62. for t in range(0, ilist[-1][2], 10):
  63. if (t >= ilist[i1][2]): i1 += 1;
  64. if (t >= r2list[i2][2]): i2 += 1;
  65. ilr = gety(r2list, i2, t) * YU2 / R2
  66. vlr = gety(ilist, i1, t) * YU1
  67. plr = ilr * vlr / 1000
  68. pr = vlr * vlr / R3 / 1000
  69. pl = plr - pr
  70. e += pl
  71. output("Input", e)
  72.  
  73. e = 0.0
  74. i1 = 0
  75. for t in range(0, olist[-1][2], 10):
  76. if (t >= olist[i1][2]): i1 += 1;
  77. vlr = gety(olist, i1, t) * YU1
  78. pr = vlr * vlr / R3 / 1000
  79. e += pr
  80. output("Output", e)
  81.  
Success #stdin #stdout 0.01s 23296KB
stdin
L 400 6700 1200 5800 *
L 1200 5800 2000 5300 *
L 2000 3300 2700 4200 *
L 2700 4200 3300 4600 *
L 3300 4600 4100 4800 *
L 4100 4800 5300 4900 *
L 5300 4900 7400 5000 *
L 400 1900 1400 2100 *
L 1400 2100 2000 2100 *
L 0 5000 7900 5000 *
L 0 0 7900 0 *
stdout
Input power was 5.183 uW
Output power was 5.675 uW