Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 186 lines (167 sloc) 7.035 kb
73c5f58 @junethack first major commit
authored
1 require 'rubygems'
b5d0cb7 @bhaak Gemfile for bundler support
bhaak authored
2 require "bundler/setup"
8b00178 @bhaak Calculate clan points
bhaak authored
3 require 'sinatra'
73c5f58 @junethack first major commit
authored
4 require 'database'
5 require 'fetch_games'
6 require 'date'
19dea9e @bhaak require 'trophyscore'
bhaak authored
7 require 'trophyscore'
49d01ff @bhaak Add new table NormalizedDeath for unique death calculations
bhaak authored
8 require 'normalize_death'
12e5e6a @bhaak Synchronize write access to db
bhaak authored
9 require 'sync'
10
11 $db_access = Sync.new
19dea9e @bhaak require 'trophyscore'
bhaak authored
12
73c5f58 @junethack first major commit
authored
13 namespace :bogus do
14
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
15 names = %w(r4wrmage ad3on k3rio bh44k c4smith789 st3nno) #hi #junethack
16 task :init do
8d302ab @bhaak Wrap games creation and dummy user creation in transactions
bhaak authored
17 User.transaction do
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
18 Rake::Task['bogus:add_servers'].invoke
19 for name in names
20 puts "creating user and account #{name}"
21 Rake::Task['bogus:add_user'].invoke(name)
22 Rake::Task['bogus:add_user'].reenable
23 end
24 Rake::Task['bogus:add_game'].invoke 20
8d302ab @bhaak Wrap games creation and dummy user creation in transactions
bhaak authored
25 end
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
26 end
bd524d8 @junethack added clans (Not tested yet)
authored
27
b976d49 add xiella's server page, add individual server page (/server/abbrev)
Ryan K authored
28 task :add_server, :name, :variant, :url, :xlogurl, :configfileurl do |t, args|
52d67f6 @junethack added events and carried properties to the game model for acehack
authored
29 puts "add server got #{args.inspect}"
b976d49 add xiella's server page, add individual server page (/server/abbrev)
Ryan K authored
30 Server.create(:name => args[:name], :variant => args[:variant], :url => args[:url], :xlogurl => args[:xlogurl], :configfileurl => args[:configfileurl])
12c23cc @bhaak add account verification
bhaak authored
31 end
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
32 task :add_servers do
d85c603 @bhaak location of nethack.eu rc-files, fix rc-files location for local test se...
bhaak authored
33 Server.create(:name => "test server 1", :url => "localhost", :xlogurl => "file://test_xlog.txt", :xloglastmodified => "1.1.1970", :xlogcurrentoffset => 0, :configfileurl => "text_xlog_random_user.rc")
34 Server.create(:name => "test server 2", :url => "localhost", :xlogurl => "file://test_xlog2.txt", :xloglastmodified => "1.1.1970", :xlogcurrentoffset => 0, :configfileurl => "text_xlog2_random_user.rc")
bc3d900 Rakefile requires skrypt now
stenno authored
35 puts "added #{ Server.all.length } test servers"
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
36 end
73c5f58 @junethack first major commit
authored
37
38
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
39 task :add_user, :name, :servername do |t, args|
40
41 puts "args were: #{args.inspect}"
42 raise "No user name specified" unless args[:name]
87f1a57 purged the :name property of User
stenno authored
43 user = User.new(:login => args[:name])
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
44 user.password = args[:name]
45 user.save
46 if args[:servername]
47 acc = Account.create(:user => user, :server => Server.get(:name => args[:servername]), :name => args[:name], :verified => true)
48 else
49 acc = Account.create(:user => user, :server => Server.get(1), :name => args[:name], :verified => true)
50 acc2 = Account.create(:user => user, :server => Server.get(2), :name => args[:name], :verified => true)
51 end
52 end
73c5f58 @junethack first major commit
authored
53
a192787 @Noeda Add a rake command to add a lot of games (500) at a time and fix not all...
Noeda authored
54 task :add_a_lot_of_games do
55 Rake::Task['bogus:add_game'].invoke 500
56 end
57
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
58 task :add_game, :games do |t, args|
59
600de1b Server updates hourly. Scores are working.
nooodl authored
60 deaths = [ #some deaths, feel free to add more :P #done -nooodl
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
61 "killed by a newt",
62 "petrified by a chickatrice corpse",
63 "killed by a soldier ant",
64 "killed by a mumak",
65 "killed by a minotaur",
66 "killed by a hallucinogen-distorted woodchuck",
67 "drowned in a moat by a giant eel",
68 "killed by brainlessness",
69 "killed by Vlad the Impaler, while helpless",
70 "killed by the Wizard of Yendor",
600de1b Server updates hourly. Scores are working.
nooodl authored
71 "killed by self-genocide",
72 "killed by overexertion",
73 "died of starvation",
74 "killed by a touch of death",
75 "poisoned by Pestilence",
76 "killed by a death ray",
77 "escaped",
78 "dissolved in molten lava",
79 "killed by an Archon",
80 "killed by Master Kaen",
81 "ascended",
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
82 ]
83 args.with_defaults(:games => 1)
5e0ba95 @junethack replaced echo with File >_>
authored
84 xlog1 = File.open "test_xlog.txt", "a"
85 xlog2 = File.open "test_xlog2.txt", "a"
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
86 args[:games].to_i.times do
87 gender = ["Fem", "Mal"][rand 2]
88 align = ["Law","Neu","Cha"][rand 3]
a192787 @Noeda Add a rake command to add a lot of games (500) at a time and fix not all...
Noeda authored
89 death = deaths[rand 21]
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
90 game = {
91 :name => names[rand 6],
92 :deaths => rand(3),
93 :deathlev => rand(30) + 1,
94 :realtime => rand(10000) + 10000,
95 :turns => rand(1000) + 200,
0453146 make the dates for bogus games fall within next year's tournament dates
Ryan K authored
96 :birthdate => Time.utc(2012, 6, 2).strftime("%Y%m%d"),
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
97 :conduct => rand(4096), #some bitmask (wrong)
98 :nconducts => rand(12), #as of now, does not match with the 'conduct' property
99 :role => %w(Arc Bar Cav Hea Kni Mon Pri Ran Rog Sam Tou Val Wiz)[rand 13],
100 :deathdnum => rand(57) - 5,
101 :gender => gender,
102 :gender0 => gender,
103 :uid => 5, #dunno what that does
104 :maxhp => rand(250) + 10,
105 :points => rand(350000),
0453146 make the dates for bogus games fall within next year's tournament dates
Ryan K authored
106 :deathdate => Time.utc(2012, 6, 3).strftime("%Y%m%d"),
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
107 :version => "3.4.3",
108 :align => align,
109 :align0 => align,
0453146 make the dates for bogus games fall within next year's tournament dates
Ryan K authored
110 :starttime => Time.utc(2012, 6, 2).to_i, #too lazy for realistic values...
111 :endtime => Time.utc(2012, 6, 3).to_i,
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
112 :achieve => rand(4096), #wrong here, too lazy
113 :hp => death == "ascended" ? rand(250) + 10 : rand(10) - 10,
114 :maxlvl => rand(57),
115 :death => death,
116 :race => %w(Dwa Hum Gno Elf)[rand 4],
117 :flags => nil #dunno what that does
118 }
bf7f451 I am a total idiot
Ryan K authored
119 [xlog1, xlog2][rand 2].puts game.to_xlog
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
120 end
46f9708 @junethack started clan markup/routes
authored
121 xlog1.close
122 xlog2.close
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
123 end
12c23cc @bhaak add account verification
bhaak authored
124
125 task :test_account_verification, :server_id, :user do |t, args|
126 server = Server.get(args[:server_id])
127 raise "verification failed for #{args[:user]} on server #{server.name}" unless server.verify_user(args[:user], Regexp.new("junethack2011 testuser"))
128 end
73c5f58 @junethack first major commit
authored
129 end
130
131 namespace :fetch do
48c3520 All tabs now 4 spaces.
Mauris Van Hauwe authored
132 task :get_games do
133 fetch_all
134 end
73c5f58 @junethack first major commit
authored
135 end
db82e60 @bhaak record competition trophies for ascended games in Scoreentry
bhaak authored
136
137 namespace :update do
a07ee80 @bhaak Output numbered games when doing update:scores
bhaak authored
138 i = 0
db82e60 @bhaak record competition trophies for ascended games in Scoreentry
bhaak authored
139 task :scores do
140 (repository.adapter.select "select version,id,ascended from games where user_id is not null order by endtime").each {|game|
a07ee80 @bhaak Output numbered games when doing update:scores
bhaak authored
141 i += 1
142 puts "#{i} #{game.version}"
db82e60 @bhaak record competition trophies for ascended games in Scoreentry
bhaak authored
143 update_scores(Game.get(game.id))
144 }
145 end
b0ae639 @bhaak Rake task for updating nconducts
bhaak authored
146
73250cc @bhaak Variant specific competition score entries
bhaak authored
147 task :user_competition do
148 (repository.adapter.select "select version,id,ascended from games where user_id is not null and ascended='t' order by endtime").each {|game|
149 i += 1
150 puts "#{i} #{game.version}"
151 update_competition_scores_ascended(Game.get(game.id))
152 }
153 end
154
b0ae639 @bhaak Rake task for updating nconducts
bhaak authored
155 # only update nconducts field
156 task :nconducts do
157 i = 0
158 Game.all.each do |game|
159 game.nconducts = (Integer game.conduct).to_s(2).count("1")
160 i += 1
161 puts i
162 game.save! # only change field and don't call hooks
163 end
164 end
8b00178 @bhaak Calculate clan points
bhaak authored
165
b123672 @bhaak Show clan scoring on /scoreboard
bhaak authored
166 task :clan_winner do
8b00178 @bhaak Calculate clan points
bhaak authored
167 score_clans
168 end
49d01ff @bhaak Add new table NormalizedDeath for unique death calculations
bhaak authored
169
170 task :normalize_deaths do
171 (repository.adapter.select "select version,id,ascended from games where user_id is not null order by endtime").each {|game|
172 i += 1
173 puts "#{i} #{game.version}"
174 normalize_death(Game.get(game.id))
175 }
176 end
55be5f1 @bhaak Calculation of "All Conducts/Roles/Races/Alignments/Genders"
bhaak authored
177
178 task :all_stuff do
179 (repository.adapter.select "select version,id,ascended from games where user_id is not null and ascended='t' order by endtime").each {|game|
180 i += 1
181 puts "#{i} #{game.version}"
182 update_all_stuff(Game.get(game.id))
183 }
184 end
db82e60 @bhaak record competition trophies for ascended games in Scoreentry
bhaak authored
185 end
Something went wrong with that request. Please try again.