Commits

Wang Dingwei committed 630ab42

feature: preload time and stage display

Comments (0)

Files changed (12)

-Rack Query System is a web frontend for Burning test records. It's written in Flask and largely immitated the flask examples. 
+Rack Query System is a web frontend for Burning test records. 
 
 Requirements
 ------------
 * By PD line
 * By Service Tag, MO, or the unit serial number
 * Unit checkin(only for test purposes), checkout, and rack change.
+* Unite checkout
+* Export to Excel
+* Unit stage query
+* Preload times query
+
 
 There are a lot of todos:
 
 * More features
 * CSS and theming, it's too ugly now.
-* Try out different deployments
 
 Well, that's it for now. :)

rqs/application.py

         (views.checkout, "/checkout"),
         (views.change_rack, "/change_rack"),
         (views.export, "/export"),
+        (views.preload, "/preload"),
         )
 
 def create_app(config=None, app_name=None, modules=None):
             if hasattr(self, k):
                 setattr(self, k, v)
         self.delay = 0
+        self.stage = None
 
     def __repr__(self):
         return '<Unit %r>' % self.ServiceTag
         client = current_app.config['SOAP_CLIENT']
         result = client.service.GetNextStage(svctag, 'AO', 'AO')
         self.stage = result.split()[0]
+
+class Preload(db.Model):
+    __tablename__ = 'preload'
+    Id = db.Column(db.Integer, primary_key=True)
+    ServiceTag = db.Column(db.String(7))
+    PPID = db.Column(db.String(30))
+    MACID = db.Column(db.String(12))
+    Downloadtime = db.Column(db.DateTime)
+    def __repr__(self):
+        return "<preload record %s>" % self.Id

rqs/templates/by_line.html

     // Color up unit indicators
     var times = $(".unitpos");
     for (var i=0; i<=times.length; i++) {
-      var value = Math.round($(times[i]).text() / 3600);
-      $(times[i]).text(value);
-      if (value < 4) {
-        $(times[i]).css("background-color", "#C0FF3E");
-      }
-      else if (value >= 4 ) {
-        $(times[i]).css("background-color", "#FFA07A");
-      }
-      //else if (value >=2) {
-      //  $(times[i]).css("background-color", "#FFEC8B");
-      //}
+	  var udata = $(times[i]).text().split('-');
+	  var uage = Math.round(udata[0] / 3600);
+	  var ustage = udata[1];
+      $(times[i]).text(uage);
+      switch(ustage) {
+		case 'TO': 		// Runin
+		$(times[i]).css("background-color", "#F5BCA9");
+		break;
+		case 'TV':		// Preload
+		$(times[i]).css("background-color", "#F2F5A9");
+		break;
+		case 'IO':		// Packing
+		$(times[i]).css("background-color", "#BCF5A9");
+		break;
+		default:
+		$(times[i]).css("background-color", "#E6E6E6");
+	  }  
     }
 
     // Formatting ### seconds into "# hours ## seconds"
 
 <h2>{{ self.title() }}</h2>
 
-{% for (rack, all_units, delayed_units, avg_delay, max_delay) in delayed %}
+{% for (rack, all_units, delayed_units, max_age) in delayed %}
 <div class='rackinfo'>
   <span class='rackdesc'>
   <em><a href="{{ url_for('line.rack_info', line=line, rack=rack) }}">{{ rack }}</a></em>, 
   <em>{{ delayed_units|length }}/{{ all_units|length }}</em>,
-  <em><span class="seconds" >{{ max_delay }}</span></em>
+  <em><span class="seconds" >{{ max_age }}</span></em>
   </span>
 <span class='rackunits'>
   {% for unit in all_units %}
-  <a href="{{ url_for('svctag.by_svctag', svctag=unit.ServiceTag) }}"><div class="unitpos">{{ unit.age }}</div></a>
+  <a href="{{ url_for('svctag.by_svctag', svctag=unit.ServiceTag) }}">
+  <div class="unitpos">{{ unit.age }}-{{ unit.stage }}</div>
+  </a>
   {% endfor %}
 </span>
 </div>

rqs/templates/layout.html

             <li><a href="{{ url_for('checkin.check_in')}}" target="_blank">Check in</a></li>
             <li><a href="{{ url_for('change_rack.update_rack') }}" target="_blank">Update Rack</a></li>
             <li><a href="{{ url_for('export.export_csv') }}">Export Data</a></li>
+			<li><a href="{{ url_for('preload.frontend') }}">Preload Times</a></li>
           </ul>
           <h3>Query</h3>
           <dl>

rqs/templates/preload_query.html

+{% extends "layout.html" %}
+{% block title %}
+Preload Times
+{% endblock %}
+
+{% block body %}
+
+<script>
+</script>
+
+<h2>{{ self.title() }}</h2>
+
+<dl>
+<dt>By service tag:</dt>
+<dd><form action='.' method='POST'>
+<input name="svctag" size="8">
+<input type="submit" value="Submit">
+</form></dd>
+<dt><a href="{{ url_for('getall') }}">All Delayed</a></dt>
+</dl>
+
+{% endblock %}

rqs/templates/preload_times.html

+{% extends "layout.html" %}
+{% block title %}
+Preload Times
+{% endblock %}
+
+{% block body %}
+
+<script>
+</script>
+
+<h2>{{ self.title() }}</h2>
+
+<table>
+<tr><th>Service Tag</th><th>Times</th></tr>
+{% for svctag, times in result %}
+<tr><td><a href="{{ url_for('getone', svctag=svctag) }}">{{ svctag }}</a></td><td>{{ times }}</td></tr>
+{% endfor %}
+</table>
+
+{% endblock %}

rqs/templates/preload_unit.html

+{% extends "layout.html" %}
+{% block title %}
+Preload Times by Unit
+{% endblock %}
+
+{% block body %}
+
+<script>
+</script>
+
+<h2>{{ self.title() }}</h2>
+
+<ul>
+{% for p in result %}
+<li>{{ p.Downloadtime }}</li>
+{% endfor %}
+</ul>
+
+{% endblock %}

rqs/views/__init__.py

 from .checkout import checkout
 from .checkin import checkin
 from .change_rack import change_rack
-from .export import export
+from .export import export
+from .preload import preload

rqs/views/line.py

 
 from rqs.model import db, Unit
 from rqs.extensions import cache
-from rqs.util import outside_runin, get_stage, outsiders
+from rqs.util import outside_runin, get_stage, outsiders, getstages
 
 from collections import defaultdict
 
-
 line = Module(__name__)
 
 @line.route('/', methods=['GET', 'POST'])
                 units.remove(u)
                 db.session.delete(u)
             db.session.commit()
-            #for u in units[:]:
-                #if u.age > app.config['MAXAGE'] and \
-                #        outside_runin(u.ServiceTag, app.config['SOAP_CLIENT']):
-                #    units.remove(u)
-                #    db.session.delete(u)
-            #db.session.commit()
-        
-        delayed_units = [u for u in units if u.delay > 0]
-        
-        if delayed_units:
-            avg_delay = sum([u.delay for u in delayed_units]) / len(delayed_units)
-        else:
-            avg_delay = 0
         
         if units:
-            max_delay = max([u.delay for u in units])
-        else:
-            max_delay = 0
-			
-        delay_by_rack.append((rack, units, delayed_units, avg_delay, max_delay))
+            delayed_units = getstages([u for u in units if u.delay > 0], 
+                                    app.config['SOAP_CLIENT'])
+        
+            max_age = max([u.age for u in units])
+        
+            delay_by_rack.append((rack, units, delayed_units, max_age))
 
-    delay_by_rack.sort(key=lambda x: x[4], reverse=True)
+    delay_by_rack.sort(key=lambda x: x[3], reverse=True)
 
     return render_template('by_line.html',
                            delayed = delay_by_rack,

rqs/views/preload.py

+from flask import Module, session, request, redirect, url_for, \
+        render_template, g, flash, abort
+
+from flask import current_app as app
+
+from rqs.model import db, Preload
+from rqs.extensions import cache
+
+from operator import itemgetter
+from collections import defaultdict
+
+preload = Module(__name__)
+
+@preload.route('/', methods=['GET', 'POST'])
+def frontend():
+    if request.method == 'POST':
+        svctag = request.form['svctag']
+        if svctag:
+            return redirect(url_for('getone', svctag=svctag))
+    return render_template('preload_query.html')
+
+    
+@preload.route('/one/<svctag>')
+def getone(svctag):
+    records = Preload.query.filter_by(ServiceTag=svctag)
+    return render_template('preload_unit.html', result=records)
+    
+
+@preload.route('/top/<int:num>')
+def gettop(num):
+    return
+
+
+@preload.route('/all/')
+def getall():
+    result = Preload.query.all()
+    dup = defaultdict(int)
+    for unit in result:
+        dup[unit.ServiceTag] += 1
+    for s in dup.keys():
+        if dup[s] <= 1:
+            del dup[s]
+    dup2 = sorted([(k, v) for (k, v) in dup.items()], 
+                  key=itemgetter(1), reverse=True)
+    return render_template('preload_times.html', result=dup2)
 
 setup(
     name='rqs',
-    version='0.4',
+    version='0.5',
     url='<enter URL here>',
     license='BSD',
     author='Joel Wang',