Generating everything up front so that we can switch at the quarter

boundaries right away.
This commit is contained in:
Kohsuke Kawaguchi 2014-03-21 17:35:36 -07:00
parent b0caf7fe3c
commit ab9905795e
3 changed files with 30 additions and 19 deletions

View File

@ -9,27 +9,32 @@ def xml = new XmlSlurper().parse("messages.xml")
def dt = new Date()
dt = "${dt.year+1900}Q${1+((int)dt.month/3)}"
def slots = xml.slots.find{ it.@time==dt }
def all = [:];
int s = 0;
def messageCounts = [];
def slots = xml.quarter.each { q ->
def messageCounts = [];
all[q.@time.text()] = messageCounts
if (slots!=null) {
slots.slot.each { slot ->
for (int i=0; i<((slot.@weight?.text() ?: 1) as int); i++) {// repeat for each weight of each slot
int m = 0;
slot.message.each { msg ->
generate(msg, "output/message-${s}_${m}.html");
m++;
}
messageCounts << m;
s++;
int s = 0;
q.slot.each { slot ->
for (int i=0; i<((slot.@weight?.text() ?: 1) as int); i++) {// repeat for each weight of each slot
int m = 0;
slot.message.each { msg ->
generate(msg, "output/${q.@time}-${s}_${m}.html");
m++;
}
messageCounts << m;
s++;
}
}
}
}
new File("output/message.html").text = new File("message.html").text.replace("[1,1,2]",messageCounts.toString());
new File("output/message.html").text = new File("message.html").text.replace("{DATA}",toHash(all));
def toHash(m) {
"{"+m.collect { k,v -> " '${k}':$v " }.join(',')+"}"
}
def generate(msg,name) {
def caption = msg.caption.text()

View File

@ -2,16 +2,22 @@
<html>
<body>
<script>
var msgs = [1,1,2];
var data = {DATA};
function rnd(max) {
return Math.floor(Math.random()*max);
}
var dt = new Date()
var t = (dt.getYear()+1900)+"Q"+(Math.floor(dt.getMonth()/3)+1);
var msgs = data[t] || [];
var slot = rnd(4);
if (slot<msgs.length) {
var m = rnd(msgs[slot]);
location.href = "message-"+slot+"_"+m+".html";
var p = t+"-"+slot+"_"+m+".html"
location.href = p;
}
</script>
</body>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<patrons>
<slots time="2014Q1"><!-- test slot -->
<quarter time="2014Q1"><!-- test slot -->
<slot weight="2">
<contact>lwells@cloudbees.com</contact>
<message>
@ -28,5 +28,5 @@
</slot>
<!-- 1 slot unused -->
</slots>
</quarter>
</patrons>