source: trunk/DataCheck/DataCheck/InfoForMWL.sh @ 19471

Last change on this file since 19471 was 19471, checked in by dorner, 7 weeks ago
adapted to mysql-usage on gate
  • Property svn:executable set to *
File size: 2.9 KB
Line 
1#!/bin/bash
2#
3# script to read observation information from the database
4# format: as given by David
5# MJD DATE START STOP FLUX COMMENT
6# for times before midnight: eg 22:33 -> -01:27
7
8
9source `dirname $0`/../Sourcefile.sh
10printprocesslog "INFO starting $0 $1"
11
12function get_table()
13{
14   printprocesslog "INFO writing "$file
15   query="SELECT Datediff(Max(fRunStop), '1858-11-17') as MJD, "
16   query=$query" Date_format(Max(fRunStop), '%Y/%m/%d') as DATE, "
17   #query=$query" Date_format(Min(fRunStart), '%H:%i') as STARTOLD, "
18   query=$query" if(Hour(Min(fRunStart))>10, Concat('-', Time_format(Addtime(Timediff(Concat(STR_TO_DATE(fNight, '%Y%m%d'), ' 23:59:59'), Min(fRunStart)), '0 0:1:0.0'), '%H:%i')), Date_format(Min(fRunStart), '%H:%i')) as START, "
19   #query=$query" Date_format(Max(fRunStop), '%H:%i') as STOPOLD, "
20   query=$query" if(Hour(Max(fRunStop))>10, Concat('-', Time_format(Addtime(Timediff(Concat(STR_TO_DATE(fNight, '%Y%m%d'), ' 23:59:59'), Max(fRunStop)), '0 0:1:0.0'), '%H:%i')), Date_format(Max(fRunStop), '%H:%i')) as STOP, "
21   query=$query" CONCAT('---') as FLUX, "
22   #query=$query" CONCAT('#') as Comments"
23   #query=$query" CONCAT('# ', Timediff(Max(fRunStop), Min(fRunStart)), ' ontime: ', Convert(Sum(Time_to_sec(Timediff(fRunStop, fRunStart)))/60./60., decimal(2,1))) AS Comments"
24   query=$query" IF (ISNULL(Sum(fOnTime)), CONCAT('#'), CONCAT('# ontime: ', Convert(Sum(fOntime)/3600, decimal(2,1)), 'h')) AS Comments"
25   query=$query" FROM RunInfo "
26   query=$query" WHERE fSourceKEY="$sourcekey
27   query=$query" AND fRunTypeKEY=1 "
28   query=$query" AND fNight BETWEEN "$start" AND "$stop
29   query=$query" GROUP BY fNight "
30   query=$query" ORDER BY fNight "
31   #echo $query
32   #echo ""
33   printprocesslog "DEBUG sendquery QUERY: "$query
34   # sendquery can't be used as it writes everything into a variable
35   mysql --defaults-file=$sqlrc -s -e " $query " > $file
36}
37
38##mrk501
39#sourcekey=2
40#file="Mrk501_FACT_observations_2014.txt"
41#start=20140101
42#stop=20141030
43#get_table
44#exit
45
46#mrk421
47sourcekey=1
48
49file="Mrk421_FACT_observations_all.txt"
50start=20111115
51stop=20200101
52get_table
53
54file="Mrk421_FACT_observations_2011_2012.txt"
55start=20120101
56stop=20120701
57get_table
58
59file="Mrk421_FACT_observations_2012_2013.txt"
60start=20121001
61stop=20130930
62get_table
63
64file="Mrk421_FACT_observations_2013_2014.txt"
65start=20131001
66stop=20140930
67get_table
68
69file="Mrk421_FACT_observations_2014_2015.txt"
70start=20141001
71stop=20150930
72get_table
73
74
75#mrk501
76sourcekey=2
77
78file="Mrk501_FACT_observations_all.txt"
79start=20120501 #really started at 19.5.2012
80stop=20200101
81get_table
82
83file="Mrk501_FACT_observations_2012.txt"
84start=20120501 
85stop=20121030
86get_table
87
88file="Mrk501_FACT_observations_2013.txt"
89start=20130101 
90stop=20131030
91get_table
92
93file="Mrk501_FACT_observations_2014.txt"
94start=20140101 
95stop=20141030
96get_table
97
98file="Mrk501_FACT_observations_2015.txt"
99start=20150101 
100stop=20151030
101get_table
102
Note: See TracBrowser for help on using the repository browser.