source: trunk/web/addons/toga/search.php @ 142

Last change on this file since 142 was 142, checked in by bastiaans, 19 years ago

web/addons/toga/libtoga.php:

  • Fixed typo

web/addons/toga/search.php:

  • Timebased searching works now
File size: 6.3 KB
Line 
1<?php
2
3global $clustername, $tpl;
4
5function validateFormInput() {
6        global $clustername, $tpl, $id, $user, $name, $start_from_time, $start_to_time, $queue;
7        global $end_from_time, $end_to_time;
8
9        $error = 0;
10
11        $none_set = 0;
12
13        //if( $id == '' or $user == '' or $name == '' or $start_from_time == '' or $start_to_time == '' or $queue == '' or $end_from_time == '' or $end_to_time == '') $none_set = 1;
14
15        //if (!isset($id) and !isset($user) and !isset($start_from_time) and !isset($start_to_time) and !isset($end_from_time) and !isset($end_to_time) and !isset($queue) ) $none_set = 0;
16
17        if( $none_set ) {
18                $error = 1;
19                $error_msg = "<FONT COLOR=\"red\"><B>No search criteria set!</B></FONT>";
20        }
21
22        // doe checks en set error en error_msg in case shit
23
24        if( $error) {
25                $tpl->assign( "form_error_msg", $error_msg );
26                return 0;
27        } else {
28                return 1;
29        }
30}
31
32function makeTime( $time ) {
33
34        $days = intval( $time / 86400 );
35        $time = ($days>0) ? $time % ($days * 86400) : $time;
36
37        //printf( "time = %s, days = %s\n", $time, $days );
38
39        $date_str = '';
40        $day_str = '';
41
42        if( $days > 0 ) {
43                if( $days > 1 )
44                        $day_str .= $days . ' days';
45                else
46                        $day_str .= $days . ' day';
47        }
48
49        $hours = intval( $time / 3600 );
50        $time = $hours ? $time % ($hours * 3600) : $time;
51
52        //printf( "time = %s, days = %s, hours = %s\n", $time, $days, $hours );
53
54        if( $hours > 0 ) {
55                $date_str .= $hours . ':';
56                $date_unit = 'hours';
57        }
58
59        $minutes = intval( $time / 60 );
60        $seconds = $minutes ? $time % ($minutes * 60) : $time;
61
62        if( $minutes > 0 ) {
63
64                if( $minutes >= 10 )
65                        $date_str .= $minutes . ':';
66                else
67                        $date_str .= '0' . $minutes . ':';
68
69                $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit;
70        } else {
71                if($hours > 0 ) {
72                        $date_str .= '00:';
73                        $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit;
74                }
75        }
76
77
78        $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit;
79
80        if( $seconds > 0 ) {
81
82                if( $seconds >= 10 )
83                        $date_str .= $seconds . ' ' . $date_unit;
84                else
85                        $date_str .= '0' . $seconds . ' ' . $date_unit;
86
87        } else if ( $hours > 0 or $minutes > 0 )
88
89                $date_str .= '00 ' . $date_unit;
90
91        if( $days > 0) {
92
93                if( $hours > 0 or $minutes > 0 or $seconds > 0 )
94                        $date_str = $day_str . ' - ' . $date_str;
95                else
96                        $date_str = $day_str;
97        }
98
99        return $date_str;
100}
101
102function makeDate( $time ) {
103        return strftime( "%a %d %b %Y %H:%M:%S", $time );
104}
105
106function datetimeToEpoch( $datetime ) {
107
108        $datetime_fields = explode( ' ', $datetime );
109
110        $date = $datetime_fields[0];
111        $time = $datetime_fields[1];
112
113        $date_fields = explode( '-', $date );
114
115        $days = $date_fields[0];
116        $months = $date_fields[1];
117        $years = $date_fields[2];
118
119        $time_fields = explode( ':', $time );
120        reset( $time_fields );
121
122        print_r( $time_fields );
123
124        $hours = $time_fields[0];
125        $minutes = $time_fields[1];
126        $seconds = $time_fields[2];
127
128        $timestamp = mktime( $hours, $minutes, $seconds, $months, $days, $years );
129
130        return $timestamp;
131}
132
133function timeToEpoch( $time ) {
134
135        $time_fields = explode( ':', $time );
136
137        if( count($time_fields) == 3 ) {
138
139                $hours = $time_fields[0];
140                $minutes = $time_fields[1];
141                $seconds = $time_fields[2];
142
143        } else if( count($time_fields) == 2 ) {
144
145                $hours = 0;
146                $minutes = $time_fields[0];
147                $seconds = $time_fields[1];
148
149        } else if( count($time_fields) == 1 ) {
150
151                $hours = 0;
152                $minutes = 0;
153                $seconds = $time_fields[0];
154        }
155
156        $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) );
157
158        return $myepoch;
159}
160
161function makeSearchPage() {
162        global $clustername, $tpl, $id, $user, $name, $start_from_time, $start_to_time, $queue;
163        global $end_from_time, $end_to_time, $filter;
164
165        $tpl->assign( "cluster", $clustername );
166        $tpl->assign( "id_value", $id );
167        $tpl->assign( "user_value", $user );
168        $tpl->assign( "queue_value", $queue );
169        $tpl->assign( "name_value", $name );
170        $tpl->assign( "start_from_value", rawurldecode( $start_from_time ) );
171        $tpl->assign( "start_to_value", rawurldecode( $start_to_time ) );
172        $tpl->assign( "end_from_value", rawurldecode( $end_from_time ) );
173        $tpl->assign( "end_to_value", rawurldecode( $end_to_time ) );
174
175        if( validateFormInput() ) {
176
177                $tpl->newBlock( "search_results" );
178                $tdb = new TarchDbase();
179                if( $start_from_time ) $start_from_time = datetimeToEpoch( $start_from_time );
180                if( $start_to_time ) $start_to_time = datetimeToEpoch( $start_to_time );
181                if( $end_from_time ) $end_from_time = datetimeToEpoch( $end_from_time );
182                if( $end_to_time ) $end_to_time = datetimeToEpoch( $end_to_time );
183                $search_ids = $tdb->searchDbase( $id, $queue, $user, $name, $start_from_time, $start_to_time, $end_from_time, $end_to_time );
184
185                foreach( $search_ids as $foundid ) {
186
187                        $job = $tdb->getJobArray( $foundid );
188                        $nodes = $tdb->getNodesForJob( $foundid );
189
190                        $tpl->newBlock( "node" );
191                        $tpl->assign( "id", $job[id] );
192                        $tpl->assign( "state", $job[status] );
193                        $tpl->assign( "user", $job[owner] );
194                        $tpl->assign( "queue", $job[queue] );
195                        $tpl->assign( "name", $job[name] );
196                        $tpl->assign( "req_cpu", makeTime( TimeToEpoch( $job[requested_time] ) ) );
197                        $tpl->assign( "req_memory", $job[requested_memory] );
198
199                        $nodes_nr = count( $nodes );
200                        $domain = $job[domain];
201                        $ppn = (int) $job[ppn] ? $job[ppn] : 1;
202                        $cpus = $nodes_nr * $ppn;
203
204                        $tpl->assign( "nodes", $nodes_nr );
205                        $tpl->assign( "cpus", $cpus );
206
207                        $runningtime = intval( $job[stop_timestamp] - $job[start_timestamp] );
208                        $tpl->assign( "started", makeDate( $job[start_timestamp] ) );
209                        $tpl->assign( "finished", makeDate( $job[stop_timestamp] ) );
210                        $tpl->assign( "runningtime", makeTime( $runningtime ) );
211                       
212                        print_r( $job );
213                        print_r( $nodes );
214                        //output jobzooi
215
216                }
217               
218                if( count( $search_ids ) == 1 ) {
219
220                        $tpl->newBlock( "showhosts" );
221                }
222
223                // show search results
224
225        }
226}
227?>
Note: See TracBrowser for help on using the repository browser.