Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/chebys_by_tgt.py
Дата изменения: Fri Feb 28 14:46:08 2014
Дата индексирования: Sat Mar 1 16:38:30 2014
Кодировка:
#!/usr/bin/env python
#
#MODULE chebys_by_tgt
#
#***********************************************************************
"""

**PURPOSE** --
This report is designed to provide information on existing
Chebychev data for the given target id or time range
input. It will quickly tell the user whether or not
Chebychev data exists for the time frame and target id in
question.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --
o Converted from SQR 11/12/12 drc
"""
#***********************************************************************

__version__ = '11/12/12'

import spss_sys_util
import spst_getopt
import sys
import stpydb
import time_util

spss_db = spss_sys_util.get_environ_variable("SPSS_DB")[0]

def run(*args):
"""Usage:
do chebys_by_tgt [targetid] [starttime] [endtime] [-output=outfile]

targetid may include SQL wildcards.

starttime and endtime are SPSS time format (yyyy.ddd:hh:mm:ss).

output file name is optional. By default, output comes to the screen.
"""
legal_opts = ['output=']
options, parms = spst_getopt.spst_getopt(args, legal_opts)

if options.has_key('-output'):
outfileId = open(options['-output'], 'w')
else:
outfileId = sys.stdout

if len(parms) != 3:
raise IOError("3 and only 3 input parameters are required: target id, start time, and end time.")

targetid = parms[0].upper()
start_time = time_util.spss_time(parms[1])
end_time = time_util.spss_time(parms[2])
now = time_util.localtime()

outfileId.write('%s Chebychev Data Availability Report\n' % now.strftime('%d-%b-%Y %H:%M'))
outfileId.write(' Fit Degree\n')
outfileId.write(' Create Date Start End of Fit\n')
outfileId.write('----------------- ----------------- ----------------- ------\n')

db=stpydb.stpydb(dbmsName=spss_db)
db.query("select target_id, create_date, start_time, end_time, degree")
db.query("from qtmchebychev")
db.query('where target_id like "%s"' % targetid)
db.query('and ((start_time > %i) or (end_time > %i)) and ((start_time < %i) or (end_time < %i))' % (int(start_time), int(end_time), int(end_time), int(end_time)))
db.query('order by target_id, start_time')
result = {}
target_id = ''
while db.execute(result):
if target_id != result['target_id']:
target_id = result['target_id']
outfileId.write(' Target: %s\n' % target_id)
outfileId.write('%s %s %s %i\n' % (time_util.spss_time(result['create_date']),
time_util.spss_time(result['start_time']),
time_util.spss_time(result['end_time']),
result['degree']))

return spss_sys_util.SUCCESS

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