Commit 39a780e6 by John Doe

working on decimation handling

parent 5076e1c4
# frozen_string_literal: true
# Decimation level of a file
class DbDecimation < ActiveRecord::Base
belongs_to :db_file
end
......@@ -4,6 +4,7 @@
class DbFile < ActiveRecord::Base
belongs_to :db_folder
has_many :db_streams, dependent: :destroy
has_many :db_decimations, dependent: :destroy
accepts_nested_attributes_for :db_streams
def remove(db_service:)
......
......@@ -89,7 +89,10 @@ class UpdateDb
def __group_entries(entries)
entry_groups = {}
entries.map do |entry|
__add_to_group(entry_groups, entry[:chunks].pop, entry)
# remove the ~decimXX ending so decimations are grouped
# with their base stream
group_name = entry[:chunks].pop.gsub(/~decim[\d]+$/, '')
__add_to_group(entry_groups, group_name, entry)
end
entry_groups
end
......@@ -108,6 +111,9 @@ class UpdateDb
# convert the groups into subfolders and files
def __process_folder_contents(folder, groups)
groups.each do |name, entry_group|
# TODO
# if all paths in the entry group are the same up to a ~decim
# then this is a file, otherwise this is a subfolder
if entry_group.length == 1
__build_file(folder: folder, entry: entry_group[0], default_name: name)
elsif entry_group.length > 1
......
Rails.application.routes.draw do
resources :db_decimations
resources :nilms
resources :dbs
resources :db_streams
......
class CreateDbDecimations < ActiveRecord::Migration
def change
create_table :db_decimations do |t|
t.integer :start_time, :int, :limit=>8
t.integer :end_time, :int, :limit=>8
t.integer :total_rows, :int, :limit=>8
t.integer :total_time, :int, :limit=>8
t.integer :db_file_id, :int
t.timestamps null: false
end
end
end
class AddFieldsToFile < ActiveRecord::Migration
def change
add_column :db_decimations, :level, :integer
add_column :db_files, :start_time, :integer, limit: 8
add_column :db_files, :end_time, :integer, limit: 8
add_column :db_files, :total_rows, :integer, limit: 8
add_column :db_files, :total_time, :integer, limit: 8
end
end
......@@ -11,7 +11,19 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160522180603) do
ActiveRecord::Schema.define(version: 20160524023832) do
create_table "db_decimations", force: :cascade do |t|
t.integer "start_time", limit: 8
t.integer "int"
t.integer "end_time", limit: 8
t.integer "total_rows", limit: 8
t.integer "total_time", limit: 8
t.integer "db_file_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "level"
end
create_table "db_files", force: :cascade do |t|
t.string "name"
......@@ -20,6 +32,10 @@ ActiveRecord::Schema.define(version: 20160522180603) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "path"
t.integer "start_time", limit: 8
t.integer "end_time", limit: 8
t.integer "total_rows", limit: 8
t.integer "total_time", limit: 8
end
create_table "db_folders", force: :cascade do |t|
......
# frozen_string_literal: true
FactoryGirl.define do
factory :db_decimation do
end
end
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'DbDecimation' do
describe 'object' do
let(:db_decimation) { DbDecimation.new }
specify { expect(db_decimation).to respond_to(:level) }
specify { expect(db_decimation).to respond_to(:start_time) }
specify { expect(db_decimation).to respond_to(:end_time) }
specify { expect(db_decimation).to respond_to(:total_rows) }
specify { expect(db_decimation).to respond_to(:total_time) }
end
end
......@@ -75,9 +75,14 @@ describe 'UpdateDb' do
expect(folder1.name).to eq('first')
end
it 'builds file streams' do
it 'adds decimations to files' do
schema = Array.new(simple_db)
schema << helper.entry('/folder1/info', metadata: { name: 'first' })
schema << helper.entry('/folder1/f1_1~decim4')
schema << helper.entry('/folder1/f1_1~decim16')
update_with_schema(schema)
folder1 = @root.subfolders[0]
file1 = folder1.db_files[0]
expect(file1.db_decimations.count).to eq(2)
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment