<commit_before># coding: utf-8
require 'sinatra'
require "sinatra/json"
require 'rack'
require 'json'
require 'haml'

JSON_TYPE = 'application/json; charset=utf-8'
set :json_content_type, JSON_TYPE

get '/' do
	haml :index
end

get '/app.js' do
	coffee :app
end

get '/reserves.json' do
	json(JSON.parse(File.open('../reserves.json').read).map{|reserve|
    time = Time.at(reserve["start"] / 1000)
    title = reserve["title"]
    episode = reserve["episode"]
    if nil != episode
      title += " ##{episode}"
    end
    {
      startTime: time.strftime("%Y-%m-%d %H:%M:%S"),
      channel: reserve["channel"]["name"],
      title: title
    }
	})
end

get '/storage.json' do
  df = `df --block-size=1G /record`
  if %r{/dev/sda1\s+\d+\s+(\d+)\s+(\d+)}.match(df)
    used = $1.to_i
    free = $2.to_i
    total = used + free
    json({
      used: used,
      free: free,
      total: total,
      percentage: (100.0 * used / total).round(1),
      unit: "GB"
    })
  else
    status 500
  end
end

get '/machine-status.json' do
  temperature = `tail -n 300 ../machine-check.csv`
  json(temperature.split("\n").map{|line|
    cols = line.split(",")
    {
      time: cols[0],
      hddstate: cols[1],
      recording: cols[2],
      cpu: cols[3].to_f,
      ssd: cols[4].to_f,
      room: cols[5].to_f,<commit_msg>Change range of days at machine status.<commit_after># coding: utf-8
require 'sinatra'
require "sinatra/json"
require 'rack'
require 'json'
require 'haml'

JSON_TYPE = 'application/json; charset=utf-8'
set :json_content_type, JSON_TYPE

get '/' do
	haml :index
end

get '/app.js' do
	coffee :app
end

get '/reserves.json' do
	json(JSON.parse(File.open('../reserves.json').read).map{|reserve|
    time = Time.at(reserve["start"] / 1000)
    title = reserve["title"]
    episode = reserve["episode"]
    if nil != episode
      title += " ##{episode}"
    end
    {
      startTime: time.strftime("%Y-%m-%d %H:%M:%S"),
      channel: reserve["channel"]["name"],
      title: title
    }
	})
end

get '/storage.json' do
  df = `df --block-size=1G /record`
  if %r{/dev/sda1\s+\d+\s+(\d+)\s+(\d+)}.match(df)
    used = $1.to_i
    free = $2.to_i
    total = used + free
    json({
      used: used,
      free: free,
      total: total,
      percentage: (100.0 * used / total).round(1),
      unit: "GB"
    })
  else
    status 500
  end
end

get '/machine-status.json' do
  temperature = `tail -n #{24 * 60 / 15 * 2} ../machine-check.csv`
  json(temperature.split("\n").map{|line|
    cols = line.split(",")
    {
      time: cols[0],
      hddstate: cols[1],
      recording: cols[2],
      cpu: cols[3].to_f,
      ssd: cols[4].to_f,
      room: cols[5].to_f,
{'fraction_non_alphanumeric': 0.18558625840179238, 'fraction_numerical': 0.021657953696788648, 'mean_word_length': 2.6056527590847915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6279079', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1042, 'n_words': 232}