Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 52 lines (46 sloc) 1.237 kb
af1d3fe @patrickdevivo updates
authored
1 before = new Date().getTime()
2 Cuber = require './cuber.coffee'
3
4 mongoose = require('mongoose')
5 mongoose.connect('mongodb://heroku:cuber@staff.mongohq.com:10011/app4172676')
6 Schema = mongoose.Schema
7 ObjectId = Schema.ObjectId
8
9 Stat = new Schema({
3c44a7a @patrickdevivo update stat collection
authored
10 start_time: {type: Number}
af1d3fe @patrickdevivo updates
authored
11 total_cubes: {type: Number}
12 average_turns: {type: Number}
3c44a7a @patrickdevivo update stat collection
authored
13 time_elapsed: {type: Number}
0d3bdb1 @patrickdevivo update
authored
14 time_per_cube: {type: Number}
3c44a7a @patrickdevivo update stat collection
authored
15 accuracy: {type: Number}
af1d3fe @patrickdevivo updates
authored
16 });
3c44a7a @patrickdevivo update stat collection
authored
17 Stat = mongoose.model('Statistics', Stat)
18 first = new Stat({start_time: before, total_cubes: 0, average_turns: 0, time_elapsed: 0})
af1d3fe @patrickdevivo updates
authored
19 first.save()
3c44a7a @patrickdevivo update stat collection
authored
20 id = first._id
af1d3fe @patrickdevivo updates
authored
21
0d3bdb1 @patrickdevivo update
authored
22 jeremy = require './algorithms/jeremy/jeremy.coffee'
af1d3fe @patrickdevivo updates
authored
23 checks = 0
24 n = 0
3c44a7a @patrickdevivo update stat collection
authored
25 turns = 0
af1d3fe @patrickdevivo updates
authored
26 execute = ()->
f11be28 @patrickdevivo silence it
authored
27 cube = new Cuber.Cube n+'', false
af1d3fe @patrickdevivo updates
authored
28 solver = new Cuber.Solver cube
29 solver.import_algorithms(jeremy)
30 cube.scramble()
31 solver.go()
3c44a7a @patrickdevivo update stat collection
authored
32 # increment stuff
af1d3fe @patrickdevivo updates
authored
33 if cube.check()
34 checks++
35 n++
36 turns = turns + solver.turn_count
37 #
0d3bdb1 @patrickdevivo update
authored
38 time_elapsed = (new Date().getTime() - before)/1000
af1d3fe @patrickdevivo updates
authored
39 data = {
40 total_cubes: n
41 average_turns: turns/n
0d3bdb1 @patrickdevivo update
authored
42 time_elapsed: time_elapsed
43 time_per_cube: time_elapsed/n
3c44a7a @patrickdevivo update stat collection
authored
44 accuracy: (checks/n)*100
af1d3fe @patrickdevivo updates
authored
45 }
3c44a7a @patrickdevivo update stat collection
authored
46
47 conditions = {_id: id}
48 Stat.update(conditions, data, {upsert: true}, (err, num)-> execute() )
af1d3fe @patrickdevivo updates
authored
49
50 execute()
51
3c44a7a @patrickdevivo update stat collection
authored
52 # mongoose.connection.close()
Something went wrong with that request. Please try again.