<commit_before>class Base

  constructor: (json) ->
    for k,v of json
      @[k] = ko.observable(v)

  project_name: =>
    @vcs_url().substring(19)

  project_path: =>
    "/gh/#{@project_name()}"

  komp: (args...) =>
    ko.computed args...

#TODO: next step is to add the vcs_url, which is why I was looking at the knockout.model and knockout.mapping plugin
class Build extends Base
  constructor: (json) ->
    super(json)

    @url = @komp =>
      "#{@project_path()}/#{@build_num()}"

    @style = @komp => 'label ' + switch @status()
      when "failed"
        "important"
      when "infrastructure_fail"
        "warning"
      when "timedout"
        "important"
      when "no_tests"
        "important"
      when "killed"
        "warning"
      when "fixed"
        "success"
      when "success"
        "success"
      when "running"
        "notice"
      when "starting"
        ""

  description: (include_project) =>
    return unless @build_num?

    if include_project
      "#{@project_name()} ##{@build_num()}"
    else
      @build_num()

  github_url: =>
    "#{@vcs_url()}/commit/#{@vcs_revision()}"

  github_revision: =>
    @vcs_revision().substring 0, 8

  author: =>
    @committer_name() or @committer_email()




class Project extends Base
  constructor: (json) ->
    super(json)
    @edit_link = "#{@project_path()}/edit"
    @status = @komp =>
      if @uninferrable()
        "uninferrable"
      else if @disabled()
        "disabled"
      else if @next_build_seq?
        "active"
      else
        "inactive"



class DashboardViewModel extends Base

  constructor: ->
    @projects = ko.observableArray()
    @recent_builds = ko.observableArray()

    $.getJSON '/api/v1/projects', (data) =>
      for d in data
        @projects.push(new Project d)

    $.getJSON '/api/v1/recent-builds', (data) =>
      for d in data
        @recent_builds.push(new Build d)


  projects_with_status: (filter) => @komp =>
    p for p in @projects() when p.status() == filter






window.dashboardViewModel = new DashboardViewModel()
ko.applyBindings window.dashboardViewModel<commit_msg>Make the dashboard display real data. Add flinstone'd versions of API fns.<commit_after>class Base

  constructor: (json) ->
    for k,v of json
      @[k] = ko.observable(v)

  project_name: =>
    @vcs_url().substring(19)

  project_path: =>
    "/gh/#{@project_name()}"

  komp: (args...) =>
    ko.computed args...

#TODO: next step is to add the vcs_url, which is why I was looking at the knockout.model and knockout.mapping plugin
class Build extends Base
  constructor: (json) ->
    super(json)

    @url = @komp =>
      "#{@project_path()}/#{@build_num()}"

    @style = @komp => 'label ' + switch @status()
      when "failed"
        "important"
      when "infrastructure_fail"
        "warning"
      when "timedout"
        "important"
      when "no_tests"
        "important"
      when "killed"
        "warning"
      when "fixed"
        "success"
      when "success"
        "success"
      when "running"
        "notice"
      when "starting"
        ""

  description: (include_project) =>
    return unless @build_num?

    if include_project
      "#{@project_name()} ##{@build_num()}"
    else
      @build_num()

  github_url: =>
    "#{@vcs_url()}/commit/#{@vcs_revision()}"

  github_revision: =>
    @vcs_revision().substring 0, 8

  author: =>
    @committer_name() or @committer_email()


class Project extends Base
  constructor: (json) ->
    super(json)
    @edit_link = "#{@project_path()}/edit"

class DashboardViewModel extends Base

  constructor: ->
    @projects = ko.observableArray()
    @recent_builds = ko.observableArray()

    $.getJSON '/api/v1/projects', (data) =>
      for d in data
        @projects.push(new Project d)

    $.getJSON '/api/v1/recent-builds', (data) =>
      for d in data
        @recent_builds.push(new Build d)


  projects_with_status: (filter) => @komp =>
    p for p in @projects() when p.status() == filter






window.dashboardViewModel = new DashboardViewModel()
ko.applyBindings window.dashboardViewModel
{'fraction_non_alphanumeric': 0.14018009247992214, 'fraction_numerical': 0.0029204185933317107, 'mean_word_length': 2.570807993049522, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 38, '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': '1842103', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1335, 'n_words': 333}