Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ml klok import into fulfillment pt 2 #212

Merged
merged 6 commits into from
Sep 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 55 additions & 6 deletions app/models/klok/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Klok::Entry < ActiveRecord::Base
belongs_to :klok_project, class_name: 'Klok::Project', foreign_key: :project_id
has_one :service, through: :klok_project

delegate :local_protocol,
delegate :local_protocol,
to: :klok_project,
allow_nil: true

Expand All @@ -43,13 +43,62 @@ def end_time_stamp=(value)
super(DateTime.strptime(value,'%Q'))
end

def rounded_duration
minutes = duration/60000.0
(minutes/15.0).ceil * 15.0
def decimal_duration
minutes = duration/60000
minutes/60.0
end

def decimal_duration
rounded_duration/60.0
def klok_project_present
unless self.klok_project.present?
self.errors[:base] << 'klok project not present'
end
end

def klok_project_ssr_id
unless self.klok_project.ssr_id
self.errors[:base] << 'doesnt have SSR ID'
end
end

def klok_project_ssr_id_regex_error
unless self.klok_project.ssr_id.match(/\d\d\d\d-\d\d\d\d/)
self.errors[:base] << 'improper format - correct format is 1234-0001'
end
end

def local_project_error
unless self.local_protocol.present?
self.errors[:base] << 'no local project present'
end
end

def service_error
unless self.service.present?
self.errors[:base] << 'no service present'
end
end

def klok_person_error
unless self.klok_person.present?
self.errors[:base] << 'no klok person present'
end
end

def local_identity_error
unless self.local_identity.present?
self.errors[:base] << 'no local identity present'
end
end

def error_messages
klok_project_present
klok_project_ssr_id
klok_project_ssr_id_regex_error
local_project_error
service_error
klok_person_error
local_identity_error
return self.errors[:base]
end

def is_valid?
Expand Down
6 changes: 3 additions & 3 deletions lib/tasks/import_klok_data.rake
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ task import_klok: :environment do
####### now that we have populated the KlokShard we can bring the same data in as line items ########

CSV.open("tmp/klok_import_#{Time.now.strftime('%m%d%Y')}.csv", "wb") do |csv|
csv << ["reason", "created_at", "project_id", "resource_id", "rate", "date", "start_time_stamp_formatted",
csv << ["ssr_id", "reason", "created_at", "project_id", "resource_id", "rate", "date", "start_time_stamp_formatted",
"start_time_stamp", "entry_id", "duration", "submission_id", "device_id", "comments", "end_time_stamp_formatted",
"end_time_stamp", "rollup_to"
]
Expand All @@ -95,12 +95,12 @@ task import_klok: :environment do

if fulfillment.valid?
fulfillment.save
csv << ["Success (SRID: #{fulfillment.protocol.srid}, fulfillment ID: #{fulfillment.id}"] + entry.attributes.values
csv << ["SRID: #{fulfillment.protocol.srid}"] + ["Success (Fulfillment ID: #{fulfillment.id})"] + entry.attributes.values
else
csv << [fulfillment.errors.messages.to_s] + entry.attributes.values
end
else
csv << ['Entry not valid'] + entry.attributes.values
csv << ["N/A"] + ["Entry not valid - Reasoning: #{entry.error_messages.to_sentence}"] + entry.attributes.values
end
end
end
Expand Down