<commit_before>{argv} = require 'optimist'
Object.defineProperty global, 'KONFIG', {
  value: require('koding-config-manager').load("main.#{argv.c}")
}
{webserver, mongo, mq, projectRoot, kites, uploads, basicAuth, neo4j} = KONFIG

{loggedInPage, loggedOutPage} = require './staticpages'

webPort = argv.p ? webserver.port

processMonitor = (require 'processes-monitor').start
  name : "webServer on port #{webPort}"
  stats_id: "webserver." + process.pid
  interval : 30000
  librato: KONFIG.librato
  limit_hard  :
    memory   : 300
    callback : ->
      console.log "[WEBSERVER #{webPort}] Using excessive memory, exiting."
      process.exit()
  die :
    after: "non-overlapping, random, 3 digits prime-number of minutes"
    middleware : (name,callback) -> koding.disconnect callback
    middlewareTimeout : 5000

# Services (order is important here)
services =
  kite_webterm:
    pattern: 'webterm'
  worker_auth:
    pattern: 'auth'
  kite_applications:
    pattern: 'kite-application'
  kite_databases:
    pattern: 'kite-database'
  webserver:
    pattern: 'web'
  worker_social:
    pattern: 'social'

incService = (serviceKey, inc) ->
  for key, value of services
    if serviceKey.indexOf(value.pattern) > -1
      value.count = if value.count then value.count += inc else 1
      break

# Presences
koding = require './bongo'
koding.connect ->
  koding.monitorPresence
    join: (serviceKey) ->
      incService serviceKey, 1
    leave: (serviceKey) ->
      incService serviceKey, -1

{extend} = require 'underscore'
express  = require 'express'
Broker   = require 'broker'
request  = require 'request'
fs       = require 'fs'
hat      = require 'hat'
nodePath = require 'path'

app      = express()

# this is a hack so express won't write the multipart to /tmp
#delete express.bodyParser.parse['multipart/form-data']

app.configure ->
  app.set 'case sensitive routing', on
  app.use express.cookieParser()
  app.use express.session {"secret":"foo"}
  # app.use express.bodyParser()
  app.use express.compress()
  app.use express.static "#{projectRoot}/website/"

app.use (req, res, next)->
  res.removeHeader "X-Powered-By"
  next()

if basicAuth
  app.use express.basicAuth basicAuth.username, basicAuth.password

process.on 'uncaughtException',(err)->
  console.log 'there was an uncaught exception'
  console.log process.pid
  console.error err
#    stack = err?.stack
#    console.log stack  if stack?

koding = require './bongo'

authenticationFailed = (res, err)->
  res.send "forbidden! (reason: #{err?.message or "no session!"})", 403

Graph = require "./graph/graph"
GraphDecorator = require "./graph/graph_decorator"

_fetchActivitiesByTimestamp = (req, res)->
  graph = new Graph neo4j
  #calculate the current and next timestamp
  timestamp = req.params?.timestamp
  if not timestamp
    timestamp = new Date

  startDate = new Date timestamp
  #20*60*1000 = 1200000
  endDate = new Date(startDate.getTime() + 1200000);

  graph.fetchAll startDate.toISOString(), endDate.toISOString(), (err, rawResponse)->
    # res.send rawResponse
    GraphDecorator.decorateSingle rawResponse, (decorated)->
      res.send decorated

app.get "/-/cache/apps", (req, res)->
  _fetchActivitiesByTimestamp req, res

app.get "/-/cache/before/:timestamp", (req, res)->
  console.log "dfasdf"
  console.log  req.params
  console.log "d12341324"

  _fetchActivitiesByTimestamp req, res

app.get "/-/cache/apps", (req, res)-><commit_msg>[neo4j] fixed invalid date exception<commit_after>{argv} = require 'optimist'
Object.defineProperty global, 'KONFIG', {
  value: require('koding-config-manager').load("main.#{argv.c}")
}
{webserver, mongo, mq, projectRoot, kites, uploads, basicAuth, neo4j} = KONFIG

{loggedInPage, loggedOutPage} = require './staticpages'

webPort = argv.p ? webserver.port

processMonitor = (require 'processes-monitor').start
  name : "webServer on port #{webPort}"
  stats_id: "webserver." + process.pid
  interval : 30000
  librato: KONFIG.librato
  limit_hard  :
    memory   : 300
    callback : ->
      console.log "[WEBSERVER #{webPort}] Using excessive memory, exiting."
      process.exit()
  die :
    after: "non-overlapping, random, 3 digits prime-number of minutes"
    middleware : (name,callback) -> koding.disconnect callback
    middlewareTimeout : 5000

# Services (order is important here)
services =
  kite_webterm:
    pattern: 'webterm'
  worker_auth:
    pattern: 'auth'
  kite_applications:
    pattern: 'kite-application'
  kite_databases:
    pattern: 'kite-database'
  webserver:
    pattern: 'web'
  worker_social:
    pattern: 'social'

incService = (serviceKey, inc) ->
  for key, value of services
    if serviceKey.indexOf(value.pattern) > -1
      value.count = if value.count then value.count += inc else 1
      break

# Presences
koding = require './bongo'
koding.connect ->
  koding.monitorPresence
    join: (serviceKey) ->
      incService serviceKey, 1
    leave: (serviceKey) ->
      incService serviceKey, -1

{extend} = require 'underscore'
express  = require 'express'
Broker   = require 'broker'
request  = require 'request'
fs       = require 'fs'
hat      = require 'hat'
nodePath = require 'path'

app      = express()

# this is a hack so express won't write the multipart to /tmp
#delete express.bodyParser.parse['multipart/form-data']

app.configure ->
  app.set 'case sensitive routing', on
  app.use express.cookieParser()
  app.use express.session {"secret":"foo"}
  # app.use express.bodyParser()
  app.use express.compress()
  app.use express.static "#{projectRoot}/website/"

app.use (req, res, next)->
  res.removeHeader "X-Powered-By"
  next()

if basicAuth
  app.use express.basicAuth basicAuth.username, basicAuth.password

process.on 'uncaughtException',(err)->
  console.log 'there was an uncaught exception'
  console.log process.pid
  console.error err
#    stack = err?.stack
#    console.log stack  if stack?

koding = require './bongo'

authenticationFailed = (res, err)->
  res.send "forbidden! (reason: #{err?.message or "no session!"})", 403

Graph = require "./graph/graph"
GraphDecorator = require "./graph/graph_decorator"

_fetchActivitiesByTimestamp = (req, res)->
  graph = new Graph neo4j
  #calculate the current and next timestamp

  timestamp = if req.params?.timestamp? then parseInt(req.params.timestamp, 10) else new Date
  startDate = new Date timestamp
  #20*60*1000 = 1200000
  endDate = new Date(startDate.getTime() + 1200000);

  graph.fetchAll startDate.toISOString(), endDate.toISOString(), (err, rawResponse)->
    # res.send rawResponse
    GraphDecorator.decorateSingle rawResponse, (decorated)->
      res.send decorated

app.get "/-/cache/latest", (req, res)->
  _fetchActivitiesByTimestamp req, res

app.get "/-/cache/before/:timestamp", (req, res)->
  console.log "dfasdf"
  console.log  req.params
  console.log "d12341324"

  _fetchActivitiesByTimestamp req, res

app.get "/-/cache/apps", (req, res)->
{'fraction_non_alphanumeric': 0.12700014415453367, 'fraction_numerical': 0.015424535101628946, 'mean_word_length': 3.7815299793246036, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '946655', 'n_tokens_mistral': 2320, 'n_tokens_neox': 2219, 'n_words': 602}