Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/cyclestats.py
Дата изменения: Fri Feb 28 14:46:09 2014
Дата индексирования: Sat Mar 1 15:15:06 2014
Кодировка:

Поисковые слова: http www.badastronomy.com bad tv foxapollo.html
#!/usr/bin/env python
# Module cyclestats.py
#
# Report on cycle statistics.
#
# Translated from Ron Downes' SQR by Don Chance
#
# Modification history:
# 09-10-2013 drc Initial translation.
#
import sys
import stpydb
import time_util
import spss_sys_util
import proposal_util
from calstats import get_latest_end_time
import string

ASSIST_DB = spss_sys_util.get_environ_variable("ASSIST_DB")[0]

def get_props(cycle, prop_type, include_nophase2=False, include_failed=False):
"""Return the proposals in the input cycle of the input type.
"""
db = stpydb.stpydb(dbmsName=ASSIST_DB)
db.query('select *')
db.query('from prop_trackv')

if prop_type.find('%') == -1:
db.query('where type = "%s"' % prop_type)
else:
db.query('where type like "%s"' % prop_type)

if not include_nophase2:
db.query('and init_submit > "01-JAN-1980"')

if cycle:
db.query('and cycle = %i' % cycle)
db.query('and internal_prop != "all"')
db.query('and parallel_prop != "all"')
db.query('and prop_id > 1000')
if include_failed:
db.query('and status != "withdrawn"')
else:
db.query('and status not in ("withdrawn", "failed")')
r = {}
props = []
while db.execute(r):
props.append(proposal_util.proposal(r.copy()))
return props

def run(*args):
"""Output statistics for the input cycle or cycles.

Defaults to the current cycle. Input zero (0) for cycle 1 through the
current cycle. If the input is negative (say -n), then the last n
cycles are reported.
"""
cur_cycle = spss_sys_util.get_current_cycle()
if args:
cycles = []
for arg in args:
if int(arg) < 0:
cycles.extend(range(cur_cycle + int(arg) + 1, cur_cycle + 1))
elif int(arg) == 0:
cycles.extend(range(1, cur_cycle+1))
else:
cycles.append(int(arg))
else:
cycles = [cur_cycle]
outfile = "cyclestats.rpt"
now = time_util.spss_time()
outfileId = open(outfile, 'w')
outfileId.write('Cycle Type #_of_Props Total_Orbits Sub_Level_(%) Comp_Orbits Comp_Level_(%) Latest_date Date_report GTO/SI\n')
prop_types = ('GTO%', 'GO%', 'CAL%', 'NASA%')
for cycle in cycles:
grand_total_props = grand_total_orbits = grand_total_comp_orbits = 0
for ptype in prop_types:
pcount = len(get_props(cycle, ptype, True, True))
props = get_props(cycle, ptype)
if not props:
continue
submitted_pcount = len(props)
total_orbits = 0
comp_orbits = 0
end_time = ztime = time_util.spss_time(0)
gto_types = set()
for prop in props:
if ptype == 'GTO%':
gto_types.add(prop.get('type')[4:])
total_visits, comp_visits, max_pw_end = get_latest_end_time(prop)
for visit in prop.get_visits():
if visit.get('status') in ('failed', 'withdrawn') or visit.get('internal_su') == 'all' or visit.is_parallel() or visit.get('active_flag') != 'Y':
continue
total_orbits += visit.get('est_orbits')
if visit.get('status') == 'completed':
comp_orbits += visit.get('est_orbits')
if total_visits != comp_visits:
end_time = max_pw_end
if ztime == end_time:
latest_date = ""
else:
latest_date = end_time.strftime("%Y.%j")
if pcount == 0:
prop_percent = 0.0
else:
prop_percent = 100*float(submitted_pcount)/float(pcount)
if total_orbits == 0:
orbit_percent = 0.0
else:
orbit_percent = 100*float(comp_orbits)/float(total_orbits)
grand_total_props += pcount
grand_total_orbits += total_orbits
grand_total_comp_orbits += comp_orbits
if ptype == "GO%":
Type = "GO+DD"
else:
Type = ptype[:-1]
if ptype == "GTO%":
gtosislist = list(gto_types)
gtosislist.sort()
gtosis = string.join(gtosislist, ", ")
else:
gtosis = ""
outfileId.write('%3i %-8s %3i %4i %5.1f %4i %5.1f %8s %11s %s\n' % (cycle,
Type,
pcount,
total_orbits,
prop_percent,
comp_orbits,
orbit_percent,
latest_date,
now.strftime('%d-%b-%Y'),
gtosis))
if grand_total_orbits == 0:
grand_total_percent = 0.0
else:
grand_total_percent = 100*float(grand_total_comp_orbits)/float(grand_total_orbits)
outfileId.write('%3i Total %3i %4i %4i %5.1f %11s\n' % (cycle,
grand_total_props,
grand_total_orbits,
grand_total_comp_orbits,
grand_total_percent,
now.strftime('%d-%b-%Y')))




print "Output sent to file", outfile


if __name__ == '__main__':
if len(sys.argv) > 1:
run(*tuple(sys.argv[1:]))
else:
run()