Functions | Variables
uptime_graphic Namespace Reference

Functions

def print_header ()
 
def print_footer ()
 
def print_table (table)
 
def fill_table (table, run, t1, t2)
 
def do_fd_runs (t0, runs)
 
def do_pot (table)
 
def do_kiloton (table)
 
def main ()
 

Variables

 HTML_FILE = None
 
int DELTA_T_MIN = 20
 
 DELTA_T = timedelta(minutes=DELTA_T_MIN)
 
 HALF_DELTA_T = timedelta(minutes=DELTA_T_MIN/2)
 

Function Documentation

def uptime_graphic.do_fd_runs (   t0,
  runs 
)

Definition at line 73 of file uptime_graphic.py.

References fill_table().

Referenced by main().

73 def do_fd_runs(t0,runs):
74  tgap = timedelta(minutes=1)
75  table = []
76  tlast = t0
77  runlast = 0
78  for r in runs:
79  t1 = r['tstart']
80  t2 = r['tstop']
81  run = r['run']
82  #
83  # Check if we have a gap between this run and the previous one
84  #
85  if ((t1-tlast)>tgap):
86  #
87  # Close out the last run
88  #
89  table.append([tlast, runlast, 0, 0]) # Complete last run
90  table.append([tlast, 0, 0, 0]) # Start downtime
91  fill_table(table, 0, tlast, t1) # Fill report intervals
92  table.append([t1, 0, 0, 0]) # End of downtime
93  #
94  # Make entry for start of new run
95  #
96  table.append([t1,run,0,0])
97  fill_table(table, run, t1, t2)
98  #
99  # Prepare for next iteration
100  #
101  runlast = run
102  tlast = t2
103  return table
104 
def do_fd_runs(t0, runs)
def fill_table(table, run, t1, t2)
def uptime_graphic.do_kiloton (   table)
Add active kilotons to the table. Round to the nearest kt

Definition at line 128 of file uptime_graphic.py.

References nova_uptime.nactive_chans(), and stan::math.round().

Referenced by main().

128 def do_kiloton(table):
129  """ Add active kilotons to the table. Round to the nearest kt
130  """
131  nchanmx = 14*12*64*32
132  for row in table:
133  if (row[1]==0):
134  row[2] = 0
135  else:
136  n = nactive_chans(row[1])
137  m = 1000*round(14*n/nchanmx+0.5,0)
138  row[2] = m
139 
def do_kiloton(table)
fvar< T > round(const fvar< T > &x)
Definition: round.hpp:23
def nactive_chans(run)
Definition: nova_uptime.py:92
def uptime_graphic.do_pot (   table)

Definition at line 105 of file uptime_graphic.py.

References POTGetData.pot_between(), and nova_uptime.spills_between().

Referenced by main().

105 def do_pot(table):
106  spills = None
107  last_spill = datetime(1970,1,1)
108  for row in table:
109  t1 = row[0]-HALF_DELTA_T
110  t2 = row[0]+HALF_DELTA_T
111  #
112  # To optimize fetches from the beams database, grab spills 1
113  # day at a time
114  #
115  if ( (last_spill==None)|(t2>last_spill) ):
116  last_spill = t1 + timedelta(days=1)
117  if (last_spill<t2):
118  last_spill=t2
119  spills = spills_between(t1, last_spill)
120  pot = pot_between(t1, t2, spills)
121  #
122  # Normalize to kW. 700 kW is 1.3E17 POT/60 minutes. Our
123  # 'pot' number is in units of 1e18 pot. Then scale x100 so numbers
124  # fit on the plots with run numbers which are in 10000's range
125  #
126  row[3] = pot*(700.0/0.13)*(60./DELTA_T_MIN)*100.
127 
def spills_between(t1, t2)
Definition: nova_uptime.py:257
def pot_between(t0, t1, spills)
Definition: POTGetData.py:309
def do_pot(table)
def uptime_graphic.fill_table (   table,
  run,
  t1,
  t2 
)

Definition at line 64 of file uptime_graphic.py.

Referenced by do_fd_runs().

64 def fill_table(table,run,t1,t2):
65  if ((t2-t1)>DELTA_T):
66  tr = t1;
67  while (1):
68  tr += DELTA_T
69  table.append([tr,run,0,0])
70  if (tr>t2):
71  break
72 
def fill_table(table, run, t1, t2)
def uptime_graphic.main ( )

1D plots hits vs w //

Definition at line 140 of file uptime_graphic.py.

References nova_uptime.connect_to_database(), do_fd_runs(), do_kiloton(), do_pot(), open(), print_footer(), print_header(), print_table(), and nova_uptime.runs_for_period().

140 def main():
141  global HTML_FILE
142 
144 
145  #
146  # By default, process the current month-1 week through "now"
147  #
148  t1 = datetime.utcnow()
149  t0 = t1 - timedelta(days=33)
150  if (len(sys.argv)>1):
151  #
152  # Set the default behavior - take the date given (like
153  # 2014/08/01) and report for 1 days prior and for the rest of
154  # the month extending beyong by one day
155  #
156  t00 = datetime.strptime(sys.argv[1], "%Y/%m/%d")
157  t0 = t00 - timedelta(days=1)
158  t1 = t00 + timedelta(days=33)
159 
160  outfile_name = "uptime_graphic_%02d.%02d.html" % (t1.year, t1.month)
161  HTML_FILE = open(outfile_name,'w')
162  print_header()
163 
164  HTML_FILE.write("['Date', 'FD Run Number', "\
165  "'FD Mass (tons)', 'NuMI (kW x 100)'],")
166 
167  runs = runs_for_period(t0, t1)
168  table = do_fd_runs(t0, runs);
169  do_pot(table)
170  do_kiloton(table)
171  print_table(table)
172 
173  print_footer()
174  HTML_FILE.close()
175 
def do_fd_runs(t0, runs)
def print_table(table)
def do_kiloton(table)
def runs_for_period(day0, day1)
Definition: nova_uptime.py:140
def connect_to_database()
Definition: nova_uptime.py:52
procfile open("FD_BRL_v0.txt")
def do_pot(table)
def uptime_graphic.print_footer ( )

Definition at line 33 of file uptime_graphic.py.

Referenced by main().

34  HTML_FILE.write(\
35  "]);"
36  "var options = {"
37  "explorer: { axis: 'horizontal', maxZoomIn: 0.02857, maxZoomOut: 1.1}"
38  "};"
39  "var chart = new google.visualization.LineChart(document.getElementById('chart_div'));"
40  "chart.draw(data, options);"
41  "}"
42  "</script>"
43  "</head>"
44  "<body>"
45  " <div id=\"chart_div\" style=\"width: 900px; height: 500px;\"></div>"
46  "</body>"
47  "</html>"
48  )
49 
def uptime_graphic.print_header ( )

Definition at line 21 of file uptime_graphic.py.

Referenced by ShmRdWr.getShmRdWr(), and main().

22  HTML_FILE.write(\
23  "<html>"
24  "<head>"
25  "<script type=\"text/javascript\" src=\"https://www.google.com/jsapi\"></script>"
26  "<script type=\"text/javascript\">"
27  "google.load(\"visualization\", \"1\", {packages:[\"corechart\"]});"
28  "google.setOnLoadCallback(drawChart);"
29  "function drawChart() {"
30  "var data = google.visualization.arrayToDataTable(["
31  )
32 
def uptime_graphic.print_table (   table)

Definition at line 50 of file uptime_graphic.py.

References runNovaSAM.str.

Referenced by main().

50 def print_table(table):
51  for row in table:
52  line = "[ new Date("+\
53  str(row[0].year)+","+\
54  str(row[0].month-1)+","+\
55  str(row[0].day)+","+\
56  str(row[0].hour)+","+\
57  str(row[0].minute)+","+\
58  str(row[0].second)+"),"+\
59  str(row[1])+","+\
60  str(row[2])+","+\
61  str(row[3])+"],"
62  HTML_FILE.write(line)
63 
def print_table(table)

Variable Documentation

uptime_graphic.DELTA_T = timedelta(minutes=DELTA_T_MIN)

Definition at line 18 of file uptime_graphic.py.

int uptime_graphic.DELTA_T_MIN = 20

Definition at line 17 of file uptime_graphic.py.

uptime_graphic.HALF_DELTA_T = timedelta(minutes=DELTA_T_MIN/2)

Definition at line 19 of file uptime_graphic.py.

uptime_graphic.HTML_FILE = None

Definition at line 9 of file uptime_graphic.py.