Skip to content

Commit

Permalink
automate increasing team limits
Browse files Browse the repository at this point in the history
  • Loading branch information
Visnu Pitiyanuvath committed Aug 31, 2012
1 parent 923d587 commit c7544ff
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 19 deletions.
2 changes: 1 addition & 1 deletion models/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ util = require 'util'
mongoose = require 'mongoose'
require('mongoose-types').loadTypes mongoose

require "./#{lib}" for lib in ['invite', 'person', 'deploy', 'vote', 'team', 'service']
require "./#{lib}" for lib in ['invite', 'person', 'deploy', 'vote', 'team_limit', 'team', 'service']

module.exports = (url) ->
util.log 'connecting to ' + url.cyan
Expand Down
8 changes: 5 additions & 3 deletions models/team.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ querystring = require 'querystring'
request = require 'request'

InviteSchema = require './invite'
[Invite, Person, Deploy, Vote] = (mongoose.model m for m in ['Invite', 'Person', 'Deploy', 'Vote'])
[TeamLimit, Invite, Person, Deploy, Vote] = (mongoose.model m for m in ['TeamLimit', 'Invite', 'Person', 'Deploy', 'Vote'])

TeamSchema = module.exports = new mongoose.Schema
slug:
Expand Down Expand Up @@ -71,8 +71,10 @@ TeamSchema.static 'canRegister', (next) ->
# return next null, false, 0 # cut off team registration
Team.count {}, (err, count) ->
return next err if err
max = 101 # +1 because team fortnight labs doesn't count
next null, count < max, max - count
TeamLimit.current (err, limit) ->
return next err if err
limit++ # +1 for fortnight labs team
next null, count < limit, limit - count
TeamSchema.static 'uniqueName', (name, next) ->
Team.count { name: name }, (err, count) ->
return next err if err
Expand Down
39 changes: 39 additions & 0 deletions models/team_limit.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
mongoose = require 'mongoose'

TeamLimitSchema = module.exports = new mongoose.Schema
limit:
type: Number
required: true
effectiveAt:
type: Date
required: true
TeamLimitSchema.plugin require('../lib/use-timestamps')
TeamLimitSchema.index effectiveAt: -1

# class methods

lastLimit = null
TeamLimitSchema.static 'current', (next) ->
now = new Date

# only check every hour, unless we're near 0:00/12:00 UTC
if lastLimit?.updatedAt > now - (1000*60*60) and not @aroundMeridian(now)
next null, lastLimit.limit
else
TeamLimit.findOne { effectiveAt: { $lte: now } }, {}, { sort: [[ 'effectiveAt', -1 ]] }, (err, limit) ->
return next err if err

limit ||= new TeamLimit limit: 0, effectiveAt: now # default to 0
limit.updatedAt = now
limit.save()

lastLimit = limit

next null, limit.limit

TeamLimitSchema.static 'aroundMeridian', (now) ->
[h, m] = [now.getUTCHours(), now.getUTCMinutes()]
(h == 11 && m > 54) || (h == 12 && m < 5) || # 11:55 - 12:05
(h == 23 && m > 54) || (h == 0 && m < 5) # 23:55 - 00:05

TeamLimit = mongoose.model 'TeamLimit', TeamLimitSchema
2 changes: 1 addition & 1 deletion views/index/about.jade
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Node.js Knockout is a 48-hour hackathon featuring [node.js]. It's an online,
virtual competition with [contestants worldwide].

Coding takes place from November 10, 2012 0:00 GMT to November 12, 2012 0:00 GMT.
Coding takes place from November 10, 2012 0:00 UTC to November 12, 2012 0:00 UTC.
Judging and public voting take place the following week.

This is the third year it's been held.
Expand Down
2 changes: 1 addition & 1 deletion views/index/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ section.when
else
h1 Registration is Full
p
a( href="/teams/new" ) More spots may open at 0:00 GMT
a( href="/teams/new" ) More spots may open at 0:00 and 12:00 UTC

:markdown
P.S. This is a massively-multiplayer website: click around and chat with
Expand Down
12 changes: 6 additions & 6 deletions views/index/rules.jade
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
### 48 Hours

You've got precisely 48 hours to develop your web app during the Knockout,
not a minute more. The competition kicks off at [12:00am / 00:00 GMT on
November 10, 2012][start time] and ends at [12:00am / 00:00 GMT on November 12,
2012][end time]. Be sure you understand what time that translates to in your
local time zone.
not a minute more. The competition kicks off at [12:00 AM / 00:00 UTC on
November 10, 2012][start time] and ends at [12:00 AM / 00:00 UTC on November
12, 2012][end time]. Be sure you understand what time that translates to in
your local time zone.

Of course, feel free to work on the _concept_ for your application before the
competition starts: pretty hand-drawn pictures on napkins, angry email
Expand Down Expand Up @@ -129,8 +129,8 @@

[Email] or [tweet] us.

[start time]: http://www.wolframalpha.com/input/?i=November+10%2C+2012+0%3A00+GMT
[end time]: http://www.wolframalpha.com/input/?i=November+12%2C+2012+0%3A00+GMT
[start time]: http://www.wolframalpha.com/input/?i=November+10%2C+2012+0%3A00+UTC
[end time]: http://www.wolframalpha.com/input/?i=November+12%2C+2012+0%3A00+UTC
[GitHub]: https://github.com/
[nodejitsu]: http://nodejitsu.com/
[npm]: http://npmjs.org/
Expand Down
4 changes: 2 additions & 2 deletions views/index/scoring.jade
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ h1= title('Scoring')

## Voting

All voting will take place between 03:00 GMT on Monday, August 29 and 0:00
GMT on Tuesday, September 6.
All voting will take place between 03:00 UTC on Monday, August 29 and 0:00
UTC on Tuesday, September 6.

There will be three groups of voters:

Expand Down
2 changes: 1 addition & 1 deletion views/index/tell-me-a-story.jade
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ h2: a( href="#slide-0" ) Let's take a short hike &rarr;
:markdown
# 2012!

- November 10-12, 2012 GMT
- November 10-12, 2012 UTC
- Registration open soon
- [@node_knockout][1]

Expand Down
10 changes: 6 additions & 4 deletions views/teams/max.jade
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
:markdown
# Too many teams!

## More spots *may* open at [0:00 GMT]
### More spots *may* open at [0:00] or [12:00 UTC]

To accommodate as many people as possible, we'll be releasing more team spots
over time at [0:00 GMT] each day up until close of registration.
over time at [0:00] and [12:00 UTC] each day up until close of
registration.

Your options are:

- Be here at [0:00 GMT] when we open up more spots.
- Be here at [0:00] or [12:00 UTC] when we open up more spots.
- Check back randomly. Teams may give up their spot at any time.
- Peruse the [existing teams](/teams) and try to find one to join.
- Tweet about your misfortune (be sure to mention [@node_knockout]) and
we can try to help you find a team to join.

[0:00 GMT]: http://www.wolframalpha.com/input/?i=0:00+GMT
[0:00]: http://www.wolframalpha.com/input/?i=0:00+UTC
[12:00 UTC]: http://www.wolframalpha.com/input/?i=12:00+UTC
[existing teams]: /teams
[@node_knockout]: http://twitter.com/node_knockout

0 comments on commit c7544ff

Please sign in to comment.