makeDatasetsPage.py
Go to the documentation of this file.
1 #!/bin/env python
2 import os, sys
3 from PageConfig import PageConfig
4 from ChainData import *
5 import argparse
6 
7 import PageMaker as PM
8 #from collections import OrderedDict
9 import ViewHTML as html_view
10 import ViewGoogleCharts as google_view
11 import ProductionTestTools as tools
12 #from time import time
13 #import datetime
14 
15 prog=sys.argv[0]
16 parser = argparse.ArgumentParser(prog=prog, description='Make dataset definitions page')
17 
18 parser.add_argument("cfgFile",help="Configuration file for web-page",type=str)
19 parser.add_argument("-v","--verbose",
20  help="Print lots of debugging output",
21  action="store_true")
22 
23 args=parser.parse_args()
24 
25 cfg=PageConfig(args.cfgFile)
26 
27 pageFileName= cfg.pageFileName
28 pageTitle = cfg.pageTitle
29 pageDesc = cfg.pageDesc
30 
31 chains = cfg.chains
32 
33 
34 base_html = \
35  """
36  <div class="page-header">
37  <h1>%s</h1>
38  </div>
39  <p>
40  <!--TEXT_HOOK-->
41  </p>
42  <p>
43  The datasets for this sample are:
44  </p>
45  <div class="row">
46  <div class="container">
47  <!--LIST-->
48  </div>
49  </div>
50  """%pageTitle
51 page = PM.PageMaker(pageFileName, base_html, verbose=args.verbose)
52 page.insertContent("<!--NAVBAR_HOOK-->",
53  '<li class="active"><a href="http://nusoft.fnal.gov/nova/production/%s">%s</a></li>'%(pageFileName,pageTitle))
54 page.insertContent("NOvA | datasets",pageTitle, True)
55 page.insertContent("<!--TEXT_HOOK-->",pageDesc)
56 legend=["tier"]
57 list_html=""
58 defDescriptions=OrderedDict()
59 defInfo=OrderedDict()
60 chainTiers=[]
61 nFiles=[]
62 nEvents=[]
63 fileSizes=[]
64 for chain in chains:
65 
66  chainName=chain.name
67  if args.verbose: print "PMS : Reading data for chain " + chainName
68 
69  chainTitle=chain.title
70  chain.loadData()
71 
72  list_html += """
73  <div class="col-md-6">
74  <div class="panel panel-default">
75  <div class="panel-heading">
76  <h3 class="panel-title">%s</h3>
77  </div>
78  <div class="panel-body">
79  """%chainTitle
80  for tier in chain.tierData.keys():
81 
82  thisTier=chain.tierData[tier]
83  defName=thisTier.name
84 
85 
86  chainTierName = (chainName + "_" + tier).replace(" ","_").replace("-","_")
87  list_html += '<strong>%s</strong>: ' % tier
88  list_html += '<a href="#" data-toggle="modal" data-target="#%s">%s</a><br>'%(tools.makeAlphanumeric(chainTierName),defName)
89 
90  defDescriptions[chainTierName]=thisTier.description
91  defInfo[defName]=thisTier.summary
92 
93  try:
94  defInfo[defName]["status"]=html_view.makeSAMQueryStatusBadge(thisTier.state,time=thisTier.queryTime,date=thisTier.queryDate())
95  except:
96  defInfo[defName]["status"]=html_view.makeSAMQueryStatusBadge("Not Fetched",time=0)
97  chainTiers.append((chainTitle,tier))
98 
99  if tier not in legend:
100  legend.append(tier)
101 
102  continue
103 
104  nFiles .append( chain.getFileCounts())
105  nEvents .append(chain.getTotEventCounts())
106  fileSizes.append( chain.getTotFileSizes())
107 
108  list_html += """
109  </div>
110  </div>
111  </div>
112  """
113 
114 page.insertContent("<!--LIST-->",list_html)
115 
116 modal_html = html_view.samDefinitionDescriptionsModal(defDescriptions)
117 page.insertContent("<!--BODY_HOOK-->","%s\n<!--BODY_HOOK-->"%modal_html)
118 
119 table_html,totals = html_view.samFileInfoSummaryTable(defInfo,names=chainTiers,configs=False,status=True)
120 page.insertContent("<!--BODY_HOOK-->","%s\n<hr><!--BODY_HOOK-->"%table_html)
121 
122 head_html = ""
123 body_html = ""
124 
125 head_n_files, body_n_files = google_view.stackedColumnChart(name="n_files",
126  legend=legend,
127  results=nFiles,
128  title="Number of files per definition",
129  x_title="Chain",
130  y_title="Number of files",
131  checkbox=True)
132 head_html += head_n_files
133 body_html += body_n_files
134 
135 head_n_files, body_n_files = google_view.stackedColumnChart(name="n_events",
136  legend=legend,
137  results=nEvents,
138  title="Number of events per definition",
139  x_title="Chain",
140  y_title="Number of events",
141  checkbox=True)
142 head_html += head_n_files
143 body_html += body_n_files
144 
145 head_n_files, body_n_files = google_view.stackedColumnChart(name="size",
146  legend=legend,
147  results=fileSizes,
148  title="Size of definition",
149  x_title="Chain",
150  y_title="Size [GB]",
151  checkbox=True)
152 head_html += head_n_files
153 body_html += body_n_files
154 
155 
156 page.insertContent("<!--HEADER_HOOK-->","%s\n<!--HEADER_HOOK-->"%head_html)
157 page.insertContent("<!--BODY_HOOK-->","%s\n<!--BODY_HOOK-->"%body_html)
158 
159 
160 page.write()