This commit is contained in:
Ting-Kuan 2014-04-05 10:51:40 -04:00
commit 4e41676219
19 changed files with 581 additions and 21 deletions

View file

@ -3,4 +3,40 @@
max-width: 150px
white-space: nowrap
overflow: hidden
text-overflow: ellipsis
text-overflow: ellipsis
.bar rect
fill: steelblue
shape-rendering: crispEdges
.bar text
fill: #fff
.specialbar rect
fill: #555555
.axis path, .axis line
fill: none
stroke: #555555
shape-rendering: crispEdges
.humans-bar
fill: #bf3f3f
shape-rendering: crispEdges
.ogres-bar
fill: #3f44bf
shape-rendering: crispEdges
text
fill: #555555
.rank-text
font-size: 15px
fill: #555555
.humans-rank-text
fill: #bf3f3f
.ogres-rank-text
fill: #3f44bf

View file

@ -1,7 +1,7 @@
#my-matches-tab-view
.axis path, .axis line
fill: none
stroke: #000
stroke: #555
shape-rendering: crispEdges
.x.axis.path
display: none
@ -10,4 +10,20 @@
fill: none
stroke: steelblue
stroke-width: 1.5px
.humans-line
fill: none
stroke: #bf3f3f
stroke-width: 1.5px
.ogres-line
fill: none
stroke: #3f44bf
stroke-width: 1.5px
.axis text
stroke: none
fill: #555555
shape-rendering: crispEdges

View file

@ -16,7 +16,7 @@ block content
else
span(data-i18n="account_profile.profile") Profile
if loading
if loadingProfile
p(data-i18n="common.loading") Loading...
else if !user.get('emailHash')

View file

@ -5,21 +5,21 @@ User = require 'models/User'
module.exports = class ProfileView extends View
id: "profile-view"
template: template
loading: true
loadingProfile: true
constructor: (options, @userID) ->
super options
@user = User.getByID(@userID)
@loading = false if 'gravatarProfile' of @user
@loadingProfile = false if 'gravatarProfile' of @user
@listenTo(@user, 'change', @userChanged)
@listenTo(@user, 'error', @userError)
userChanged: (user) ->
@loading = false if 'gravatarProfile' of user
@loadingProfile = false if 'gravatarProfile' of user
@render()
userError: (user) ->
@loading = false
@loadingProfile = false
@render()
getRenderData: ->
@ -28,7 +28,7 @@ module.exports = class ProfileView extends View
grav = grav.entry[0] if grav
addedContext =
user: @user
loading: @loading
loadingProfile: @loadingProfile
myProfile: @user.id is context.me.id
grav: grav
photoURL: @user.getPhotoURL()

View file

@ -40,19 +40,19 @@ module.exports = class LadderTabView extends CocoView
checkFriends: ->
return if @checked or (not window.FB) or (not window.gapi)
@somethingLoaded("social_network_apis")
@checked = true
@addSomethingToLoad("facebook_status")
FB.getLoginStatus (response) =>
@facebookStatus = response.status
@somethingLoaded("facebook_status")
@loadFacebookFriends() if @facebookStatus is 'connected'
@somethingLoaded("facebook_status")
if application.gplusHandler.loggedIn is undefined
@listenToOnce(application.gplusHandler, 'checked-state', @gplusSessionStateLoaded)
else
@gplusSessionStateLoaded()
@somethingLoaded("social_network_apis")
# FACEBOOK
@ -67,10 +67,10 @@ module.exports = class LadderTabView extends CocoView
FB.api '/me/friends', @onFacebookFriendsLoaded
onFacebookFriendsLoaded: (response) =>
@somethingLoaded("facebook_friends")
@facebookData = response.data
@loadFacebookFriendSessions()
@somethingLoaded("facebook_friends")
loadFacebookFriendSessions: ->
levelFrag = "#{@level.get('original')}.#{@level.get('version').major}"
url = "/db/level/#{levelFrag}/leaderboard_facebook_friends"
@ -105,10 +105,10 @@ module.exports = class LadderTabView extends CocoView
application.gplusHandler.loadFriends @gplusFriendsLoaded
gplusFriendsLoaded: (friends) =>
@somethingLoaded("gplus_friends")
@gplusData = friends.items
@loadGPlusFriendSessions()
@somethingLoaded("gplus_friends")
loadGPlusFriendSessions: ->
levelFrag = "#{@level.get('original')}.#{@level.get('version').major}"
url = "/db/level/#{levelFrag}/leaderboard_gplus_friends"
@ -135,8 +135,21 @@ module.exports = class LadderTabView extends CocoView
@leaderboards[team.id]?.destroy()
teamSession = _.find @sessions.models, (session) -> session.get('team') is team.id
@leaderboards[team.id] = new LeaderboardData(@level, team.id, teamSession)
@addResourceToLoad @leaderboards[team.id], 'leaderboard', 3
render: ->
super()
@$el.find('.histogram-display').each (i, el) =>
histogramWrapper = $(el)
team = _.find @teams, name: histogramWrapper.data('team-name')
histogramData = null
$.when(
$.get("/db/level/#{@level.get('slug')}/histogram_data?team=#{team.name.toLowerCase()}", (data) -> histogramData = data)
).then =>
@generateHistogram(histogramWrapper, histogramData, team.name.toLowerCase())
getRenderData: ->
ctx = super()
ctx.level = @level
@ -149,6 +162,82 @@ module.exports = class LadderTabView extends CocoView
ctx.onGPlus = application.gplusHandler.loggedIn
ctx
generateHistogram: (histogramElement, histogramData, teamName) ->
#renders twice, hack fix
if $("#"+histogramElement.attr("id")).has("svg").length then return
histogramData = histogramData.map (d) -> d*100
margin =
top: 20
right: 20
bottom: 30
left: 0
width = 300 - margin.left - margin.right
height = 125 - margin.top - margin.bottom
formatCount = d3.format(",.0")
x = d3.scale.linear().domain([-3000,6000]).range([0,width])
data = d3.layout.histogram().bins(x.ticks(20))(histogramData)
y = d3.scale.linear().domain([0,d3.max(data, (d) -> d.y)]).range([height,0])
#create the x axis
xAxis = d3.svg.axis().scale(x).orient("bottom").ticks(5).outerTickSize(0)
svg = d3.select("#"+histogramElement.attr("id")).append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform","translate(#{margin.left},#{margin.top})")
barClass = "bar"
if teamName.toLowerCase() is "ogres" then barClass = "ogres-bar"
if teamName.toLowerCase() is "humans" then barClass = "humans-bar"
bar = svg.selectAll(".bar")
.data(data)
.enter().append("g")
.attr("class",barClass)
.attr("transform", (d) -> "translate(#{x(d.x)},#{y(d.y)})")
bar.append("rect")
.attr("x",1)
.attr("width",width/20)
.attr("height", (d) -> height - y(d.y))
if @leaderboards[teamName].session?
playerScore = @leaderboards[teamName].session.get('totalScore') * 100
scorebar = svg.selectAll(".specialbar")
.data([playerScore])
.enter().append("g")
.attr("class","specialbar")
.attr("transform", "translate(#{x(playerScore)},#{y(9001)})")
scorebar.append("rect")
.attr("x",1)
.attr("width",3)
.attr("height",height - y(9001))
rankClass = "rank-text"
if teamName.toLowerCase() is "ogres" then rankClass = "rank-text ogres-rank-text"
if teamName.toLowerCase() is "humans" then rankClass = "rank-text humans-rank-text"
message = "#{histogramData.length} players"
if @leaderboards[teamName].session? then message="#{@leaderboards[teamName].myRank}/#{histogramData.length}"
svg.append("g")
.append("text")
.attr("class",rankClass)
.attr("y",0)
.attr("text-anchor","end")
.attr("x",width)
.text(message)
#Translate the x-axis up
svg.append("g")
.attr("class", "x axis")
.attr("transform","translate(0," + height + ")")
.call(xAxis)
consolidateFriends: ->
allFriendSessions = (@facebookFriendSessions or []).concat(@gplusFriendSessions or [])
sessions = _.uniq allFriendSessions, false, (session) -> session._id
@ -213,4 +302,4 @@ class LeaderboardData extends CocoClass
allResources: ->
resources = [@topPlayers, @playersAbove, @playersBelow]
return (r for r in resources when r)
return (r for r in resources when r)

View file

@ -117,12 +117,10 @@ module.exports = class MyMatchesTabView extends CocoView
@$el.find('.score-chart-wrapper').each (i, el) =>
scoreWrapper = $(el)
team = _.find @teams, name: scoreWrapper.data('team-name')
@generateScoreLineChart(scoreWrapper.attr('id'), team.scoreHistory)
@generateScoreLineChart(scoreWrapper.attr('id'), team.scoreHistory, team.name)
generateScoreLineChart: (wrapperID, scoreHistory) =>
generateScoreLineChart: (wrapperID, scoreHistory,teamName) =>
margin =
top: 20
right: 20
@ -167,10 +165,12 @@ module.exports = class MyMatchesTabView extends CocoView
.attr("dy", ".75em")
.style("text-anchor","end")
.text("Score")
lineClass = "line"
if teamName.toLowerCase() is "ogres" then lineClass = "ogres-line"
if teamName.toLowerCase() is "humans" then lineClass = "humans-line"
svg.append("path")
.datum(data)
.attr("class","line")
.attr("class",lineClass)
.attr("d",line)

View file

@ -0,0 +1,3 @@
for /f "delims=" %%a in ('..\\utilities\\get_category.exe %*') do (
%%a
)

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<variables>
<version>1.0</version>
<author>GlenDC</author>
<copyright>CodeCombat.com © 2013-2014</copyright>
</variables>

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<variables>
<general>
<b32>
<nodejs>http://nodejs.org/dist/v0.10.25/node-v0.10.25-x86.msi</nodejs>
<ruby>http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.0.0-p353.exe?direct</ruby>
<python>http://www.python.org/ftp/python/2.7.6/python-2.7.6.msi</python>
</b32>
<b64>
<nodejs>http://nodejs.org/dist/v0.10.25/x64/node-v0.10.25-x64.msi</nodejs>
<ruby>http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.0.0-p353-x64.exe?direct</ruby>
<python>http://www.python.org/ftp/python/2.7.6/python-2.7.6.amd64.msi</python>
</b64>
<gitbash>https://msysgit.googlecode.com/files/Git-1.8.5.2-preview20131230.exe</gitbash>
</general>
<win7>
<b32>mongodb=http://fastdl.mongodb.org/win32/mongodb-win32-i386-2.5.4.zip</b32>
<b64>mongodb=http://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-2.5.4.zip</b64>
</win7>
<vista>
<b32>mongodb=http://fastdl.mongodb.org/win32/mongodb-win32-i386-2.5.4.zip</b32>
<b64>mongodb=http://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2.5.4.zip</b64>
</vista>
</variables>

View file

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<variables>
<global>
<native>English</native>
<bye>Bye Bye!</bye>
</global>
<install>
<begin>Installation has begun, this can take a while... Please stay tuned...</begin>
<close>Don't close any windows please, unless specified explicitly.</close>
</install>
<dai>
<title>[DOWNLOADING AND INSTALLING 3RD PARTY SOFTWARE]</title>
<downloading>downloading:</downloading>
<installing>installing:</installing>
<cancel>Download and Installation cancelled...</cancel>
<software>Software has been installed...</software>
<devenv>Installation of the Developers Environment is complete!</devenv>
<stop>Installation has been stopped...</stop>
<unpacking>unpacking and moving:</unpacking>
<bower>Installing bower, brunch, nodemon and sendwithus...</bower>
</dai>
<git>
<stored>CodeCombat is safely stored on a git repository.</stored>
<clapp>Therefore you need a git command-line application (Git-bash).</clapp>
<examples>Examples: git-bash, CygWin, ...</examples>
<question>Do you already have git-bash?</question>
<path>Enter the path to where you installed Git-bash</path>
<checkout>Checking out the Git Repository...</checkout>
<username>Please enter your github username:</username>
</git>
<nodejs>
<question>Do you already have the latest version of node-js installed?</question>
<path>Please enter the full path of the location you installed nodejs to:</path>
</nodejs>
<ruby>
<question>Do you already have the latest version of ruby installed?</question>
</ruby>
<mongodb>
<question>Do you already have the latest version of mongo-db installed?</question>
<path>Enter the path where you would like to install MongoDB:</path>
</mongodb>
<python>
<question>Do you already have the latest version of python installed?</question>
</python>
<error>
<xp>Sadly we can't support Windows XP... Please upgrade your OS!</xp>
<os>Machine OS cannot be determined...</os>
<osreport>Report your OS to the developers @ CodeCombat.com...</osreport>
<nocleaning>... Cleaning up has been disabled... Terminating Script!</nocleaning>
<git_app_path>The path to your git application is incorrect, please try again...</git_app_path>
<invalid_path>The path you entered is invalid, please try again...</invalid_path>
</error>
</variables>

View file

@ -0,0 +1,3 @@
powershell .\get_var.ps1 config.coco %1 > var.tmp
set /p %1= < var.tmp
del /q var.tmp

View file

@ -0,0 +1,4 @@
@ECHO off
powershell .\get_var.ps1 downloads.coco %2 %3 %4 %5 %6 > var.tmp
set /p %1= < var.tmp
del /q var.tmp

View file

@ -0,0 +1,4 @@
@ECHO off
powershell .\get_var.ps1 %1.coco %3 %4 %5 %6 %7 > var.tmp
set /p %2= < var.tmp
del /q var.tmp

View file

@ -0,0 +1,17 @@
$xml_file = [xml](get-content $args[0])
if($args.count -eq 2)
{
$xml_file.variables.($args[1])
}
elseif($args.count -eq 3)
{
$xml_file.variables.($args[1]).($args[2])
}
elseif($args.count -eq 4)
{
$xml_file.variables.($args[1]).($args[2]).($args[3])
}
elseif($args.count -eq 5)
{
$xml_file.variables.($args[1]).($args[2]).($args[3]).($args[4])
}

View file

@ -0,0 +1,2 @@
@echo off
powershell "& "%*"

View file

@ -0,0 +1,146 @@
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
#include <string>
#define tstring std::wstring
#define tcout std::wcout
static const tstring DEF_URL = L"http://www.google.com";
int ErrorReport(const tstring & str, int value = 0)
{
tcout << str.c_str();
return value;
}
void GetHashInfo(tstring id, std::vector<std::wstring> & info) {
while(id.size() > 0)
{
size_t pos = id.find(L'-');
tstring substr =
id.substr(0, pos == tstring::npos ? id.length() : pos);
info.push_back(substr);
if(pos == tstring::npos) id = L"";
else
{
++pos;
id = id.substr(pos, id.length() - pos);
}
}
}
void SetArrayVariable(
const tstring & name,
int id,
const tstring & line
)
{
tcout << L"set \"";
tcout << name;
tcout << L"[" << id << "]";
tcout << L"=" << line;
tcout << L"\"" << std::endl;
}
void FillArray(
const std::vector<tstring> & info,
const tstring & name,
const tstring & id_array_name,
const tstring & file,
int & id
)
{
if(info.size() == 0) return;
auto it = info.begin();
size_t indention = 0;
unsigned int nlc = 0;
std::wifstream infile(file.c_str(), std::ifstream::in);
if(!infile)
{
#ifdef _DEBUG
tcout << file.c_str() << std::endl;
tcout << strerror(errno) << std::endl;
#endif
return;
}
tstring line;
int counter = 1;
while (std::getline(infile, line))
{
size_t cpos = line.find('[');
if(cpos == tstring::npos)
{
cpos = line.find_first_not_of(L" \t\r\n");
}
if(nlc++ == 0 || cpos == indention)
{
indention = cpos;
if(it == info.end())
{
size_t pos = line.find(L'=') + 1;
SetArrayVariable(
name, id,
line.substr(pos, line.size() - pos)
);
SetArrayVariable(
id_array_name, id++,
line.substr(cpos, pos - 3)
);
++counter;
}
else if(line.find(*it) != tstring::npos)
{
++it;
nlc = 0;
}
}
else if(counter > 1)
{
return;
}
}
infile.close();
return;
}
int _tmain(int argc, _TCHAR* argv[])
{
if(argc == 1)
return ErrorReport(L"Please specify a localisation file.");
else if(argc == 2)
return ErrorReport(L"Please specify the name of the array.");
else if(argc == 3)
return ErrorReport(L"Please specify the name of the name-array.");
else if(argc == 4)
return ErrorReport(L"Please specify the counter parameter.");
else if(argc == 5)
return ErrorReport(L"Please specify one or more categories you are looking for.");
tstring file, name, counter_name, id_array_name;
file = argv[1];
name = argv[2];
id_array_name = argv[3];
counter_name = argv[4];
int id = 1;
for(int i = 5 ; i < argc ; ++i)
{
std::vector<tstring> information;
GetHashInfo(argv[i], information);
FillArray(information, name, id_array_name, file, id);
}
tcout << L"set \"" << counter_name << L"=" << (id - 1) << L"\"";
return 0;
}

View file

@ -0,0 +1,36 @@
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
#include <string>
#define tstring std::wstring
#define tcout std::wcout
int ErrorReport(const tstring & str, int value = 0)
{
tcout << str.c_str();
return value;
}
int _tmain(int argc, _TCHAR* argv[])
{
if(argc == 1)
return ErrorReport(L"Please specify a download URL.");
if(argc == 2)
return ErrorReport(L"Please specify a name for your variable.");
tstring url, name, extension;
url = argv[1];
name = argv[2];
if(url.find(L"exe") != tstring::npos) extension = L"exe";
else if(url.find(L"msi") != tstring::npos) extension = L"msi";
else if(url.find(L"zip") != tstring::npos) extension = L"zip";
tcout << L"set \"" << name << L"=";
tcout << extension << L"\"";
return 0;
}

View file

@ -0,0 +1,108 @@
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
#include <string>
#define tstring std::wstring
#define tcout std::wcout
static const tstring DEF_URL = L"http://www.google.com";
int ErrorReport(const tstring & str, int value = 0)
{
tcout << str.c_str();
return value;
}
void GetHashInfo(tstring id, std::vector<std::wstring> & info) {
while(id.size() > 0)
{
size_t pos = id.find(L'-');
tstring substr =
id.substr(0, pos == tstring::npos ? id.length() : pos);
info.push_back(substr);
if(pos == tstring::npos) id = L"";
else
{
++pos;
id = id.substr(pos, id.length() - pos);
}
}
}
std::wstring GetText(const std::vector<tstring> & info, const tstring & file)
{
if(info.size() == 0) return L"Info Size is 0.";
auto it = info.begin();
auto last = info.end() - 1;
size_t indention = 0;
unsigned int nlc = 0;
std::wifstream infile(file.c_str(), std::ifstream::in);
if(!infile)
{
#ifdef _DEBUG
tcout << file.c_str() << std::endl;
tcout << strerror(errno) << std::endl;
#endif
return L"File couldn't be opened.";
}
tstring line;
while (std::getline(infile, line))
{
size_t cpos = line.find('[');
if(nlc++ == 0 || cpos == indention)
{
indention = cpos;
if(line.find(*it) != tstring::npos)
{
if(it == last)
{
size_t pos = line.find(L'=') + 1;
infile.close();
return line.substr(pos, line.size() - pos);
}
else
{
++it;
nlc = 0;
}
}
}
}
infile.close();
return L"Var couldn't be found.";
}
int _tmain(int argc, _TCHAR* argv[])
{
if(argc == 1)
return ErrorReport(L"Please specify a localisation file.");
else if(argc == 2)
return ErrorReport(L"Please specify the ID you are looking for.");
tstring file, hash;
file = argv[1];
hash = argv[2];
std::vector<tstring> information;
GetHashInfo(hash, information);
size_t size = information.size();
for(unsigned int i = 0 ; i < size ; ++i)
{
tcout << information[i];
if(i != size - 1) tcout << L"_";
}
tcout << L"=" << GetText(information, file);
return 0;
}

View file

@ -36,6 +36,7 @@ LevelHandler = class LevelHandler extends Handler
return @getRandomSessionPair(req,res,args[0]) if args[1] is 'random_session_pair'
return @getLeaderboardFacebookFriends(req, res, args[0]) if args[1] is 'leaderboard_facebook_friends'
return @getLeaderboardGPlusFriends(req, res, args[0]) if args[1] is 'leaderboard_gplus_friends'
return @getHistogramData(req, res, args[0]) if args[1] is 'histogram_data'
return @sendNotFoundError(res)
@ -118,6 +119,18 @@ LevelHandler = class LevelHandler extends Handler
query = Session.find(sessionQuery).select('-screenshot')
query.exec (err, results) =>
if err then @sendDatabaseError(res, err) else @sendSuccess res, results
getHistogramData: (req, res,slug) ->
query = Session.aggregate [
{$match: {"levelID":slug, "submitted": true, "team":req.query.team}}
{$project: {totalScore: 1, _id: 0}}
]
query.exec (err, data) =>
if err? then return @sendDatabaseError res, err
valueArray = _.pluck data, "totalScore"
@sendSuccess res, valueArray
getLeaderboard: (req, res, id) ->
sessionsQueryParameters = @makeLeaderboardQueryParameters(req, id)