-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfika.html
202 lines (175 loc) · 6.89 KB
/
fika.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<meta charset="utf-8" />
<title>Fikagruppsgenerator</title>
<style>
body { padding:1em; overflow-y:scroll; }
h2 { margin-top:2em }
.tabset > input[type="radio"] {
position: absolute;
left: -200vw;
}
.tabset .tab-panel {
display: none;
}
.tabset > input:first-child:checked ~ .tab-panels > .tab-panel:first-child,
.tabset > input:nth-child(3):checked ~ .tab-panels > .tab-panel:nth-child(2),
.tabset > input:nth-child(5):checked ~ .tab-panels > .tab-panel:nth-child(3),
.tabset > input:nth-child(7):checked ~ .tab-panels > .tab-panel:nth-child(4),
.tabset > input:nth-child(9):checked ~ .tab-panels > .tab-panel:nth-child(5),
.tabset > input:nth-child(11):checked ~ .tab-panels > .tab-panel:nth-child(6) {
display: block;
}
.tabset > label {
position: relative;
display: inline-block;
padding: 15px 15px 25px;
border: 1px solid transparent;
border-bottom: 0;
cursor: pointer;
font-weight: 600;
}
.tabset > label::after {
content: "";
position: absolute;
left: 15px;
bottom: 10px;
width: 22px;
height: 4px;
background: #8d8d8d;
}
.tabset > label:hover,
.tabset > input:focus + label {
color: #06c;
}
.tabset > label:hover::after,
.tabset > input:focus + label::after,
.tabset > input:checked + label::after {
background: #06c;
}
.tabset > input:checked + label {
border-color: #ccc;
border-bottom: 1px solid #fff;
margin-bottom: -1px;
}
.tab-panel {
padding: 30px 0;
border-top: 1px solid #ccc;
}
.tabset {
max-width: 65em;
margin:auto;
}
</style>
</head>
<body>
<div class="tabset">
<input type="radio" name="tabset" id="tab2" aria-controls="walktalktab" checked>
<label for="tab2">Walk & Talk</label>
<input type="radio" name="tabset" id="tab1" aria-controls="fikatab">
<label for="tab1">Fikagrupper</label>
<div class="tab-panels">
<section id="walktalktab" class="tab-panel">
<h1>Deterministisk Walk&Talk-gruppsgenerator</h1>
<p class="lead">Nya grupper slumpas automatiskt baserat på veckonummer.</p>
<p><em>Denna generator skiljer sig från fikagruppsgeneratorn då den försöker skapa grupper om 2 istället för grupper om 4.</em></p>
<div id="walktalk" class="row"></div>
</section>
<section id="fikatab" class="tab-panel">
<h1>Deterministisk Fikagruppsgenerator</h1>
<p class="lead">Nya grupper slumpas automatiskt baserat på veckonummer. Glöm inte ta en skärmdump och posta bilden i #c-standup.</p>
<div id="fika" class="row"></div>
</section>
</div>
</div>
<script>
// the following adds the Math.seedrandom() function, making random() deterministic if given the same seed. (Technically I believe it was always deterministic, but not in a useful way.)
!function(a,b,c,d,e,f,g,h,i){function j(a){var b,c=a.length,e=this,f=0,g=e.i=e.j=0,h=e.S=[];for(c||(a=[c++]);d>f;)h[f]=f++;for(f=0;d>f;f++)h[f]=h[g=s&g+a[f%c]+(b=h[f])],h[g]=b;(e.g=function(a){for(var b,c=0,f=e.i,g=e.j,h=e.S;a--;)b=h[f=s&f+1],c=c*d+h[s&(h[f]=h[g=s&g+b])+(h[g]=b)];return e.i=f,e.j=g,c})(d)}function k(a,b){var c,d=[],e=typeof a;if(b&&"object"==e)for(c in a)try{d.push(k(a[c],b-1))}catch(f){}return d.length?d:"string"==e?a:a+"\0"}function l(a,b){for(var c,d=a+"",e=0;e<d.length;)b[s&e]=s&(c^=19*b[s&e])+d.charCodeAt(e++);return n(b)}function m(c){try{return o?n(o.randomBytes(d)):(a.crypto.getRandomValues(c=new Uint8Array(d)),n(c))}catch(e){return[+new Date,a,(c=a.navigator)&&c.plugins,a.screen,n(b)]}}function n(a){return String.fromCharCode.apply(0,a)}var o,p=c.pow(d,e),q=c.pow(2,f),r=2*q,s=d-1,t=c["seed"+i]=function(a,f,g){var h=[];f=1==f?{entropy:!0}:f||{};var o=l(k(f.entropy?[a,n(b)]:null==a?m():a,3),h),s=new j(h);return l(n(s.S),b),(f.pass||g||function(a,b,d){return d?(c[i]=a,b):a})(function(){for(var a=s.g(e),b=p,c=0;q>a;)a=(a+c)*d,b*=d,c=s.g(1);for(;a>=r;)a/=2,b/=2,c>>>=1;return(a+c)/b},o,"global"in f?f.global:this==c)};if(l(c[i](),b),g&&g.exports){g.exports=t;try{o=require("crypto")}catch(u){}}else h&&h.amd&&h(function(){return t})}(this,[],Math,256,6,52,"object"==typeof module&&module,"function"==typeof define&&define,"random");
// calculate the week number of the year, multiply by the current year, and use as seed for the random function.
function getSeed() {
let d = new Date();
d = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()));
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay()||7));
return d.getFullYear() * Math.ceil(( ( (d - new Date(Date.UTC(d.getUTCFullYear(),0,1))) / 86400000) + 1)/7);
}
function init(seed){
if(!seed)
seed = getSeed();
Math.seedrandom(seed);
let url = "ppl.json"
fetch(url)
.then(res => res.json())
.then((out) => {
populate(out.people,seed,"fika");
populate(out.people,seed,"walktalk");
})
.catch(err => { throw err });
}
function PeopleSet(list){
this.ppl = list;
}
// grab a random person from array, removing it and returning it
PeopleSet.prototype.grab = function(){
let r = Math.floor( Math.random()*this.ppl.length );
return this.ppl.splice(r,1)[0];
}
PeopleSet.prototype.length = function(){
return this.ppl.length;
}
PeopleSet.prototype.groups = function(groupCount){
let g=0;
let groups = [];
// keep taking random names from the set, and add them one after another into the different groups.
while( this.length() > 0 ) {
if( groups[ g%groupCount ] === undefined ){
groups[ g%groupCount ] = [];
}
groups[ g%groupCount ].push( this.grab() );
g++;
}
return groups;
}
// a gatekeeper decides who gets to be in this weeks groups, based on configured preferences
function GateKeeper(meetingType,seed){
this.ix = 0;
this.meetingType = meetingType;
this.seed = seed;
}
GateKeeper.prototype.willPermit = function(person) {
let personIsConfigured = person[this.meetingType] > 0;
let personIsUpForInclusion = (this.seed+(this.ix++)) % person[this.meetingType] == 0;
return personIsConfigured && personIsUpForInclusion;
}
function populate(source,seed,id){
var keeper = new GateKeeper(id,seed);
var set = new PeopleSet(source.filter( s => keeper.willPermit(s) ).map( s => s.name ));
if( id == "walktalk" )
{
let maxGroupSize = 2;
var groupCount = Math.floor(set.length() / maxGroupSize);
}
else
{
let maxGroupSize = 4;
var groupCount = Math.ceil(set.length() / maxGroupSize);
}
let groups = set.groups(groupCount);
var groupNames = ["I","II","III","IV","V","VI","VII","VIII","IX","X","XI","XII","XIII","XIV","XV"];
var str = "";
for( var group in groups ) {
str += `<div class="col-md-6"><h2>Grupp ${groupNames[group]}</h2><ul class="list-group">`;
for( var p of groups[group] ){
str += `<li class="list-group-item">${p}</li>`;
}
str += "</ul></div>\n";
}
document.getElementById(id).innerHTML = str;
}
document.body.onload = function(){
init();
}
</script>
</body></html>