|
1 | 1 | module ShotInformation::Profile
|
2 | 2 | JSON_PROFILE_KEYS = %w[title author notes beverage_type steps tank_temperature target_weight target_volume target_volume_count_start legacy_profile_type type lang hidden reference_file changes_since_last_espresso version].freeze
|
| 3 | + CSV_PROFILE_HEADERS = %w[information_type elapsed pressure current_total_shot_weight flow_in flow_out water_temperature_boiler water_temperature_in water_temperature_basket metatype metadata comment].freeze |
3 | 4 |
|
4 | 5 | def tcl_profile_fields
|
5 | 6 | @tcl_profile_fields ||= profile_fields.except("json")
|
@@ -35,4 +36,30 @@ def json_profile
|
35 | 36 |
|
36 | 37 | JSON.pretty_generate(json)
|
37 | 38 | end
|
| 39 | + |
| 40 | + def csv_profile |
| 41 | + CSV.generate do |csv| |
| 42 | + csv << CSV_PROFILE_HEADERS |
| 43 | + |
| 44 | + csv << ["meta", nil, nil, nil, nil, nil, nil, nil, nil, "Name", shot.profile_title, "text"] |
| 45 | + csv << ["meta", nil, nil, nil, nil, nil, nil, nil, nil, "Date", shot.start_time.iso8601, "ISO8601 formatted date"] |
| 46 | + csv << ["meta", nil, nil, nil, nil, nil, nil, nil, nil, "Roasting Date", Date.parse(shot.roast_date)&.iso8601, "ISO8601 formatted date"] if shot.roast_date.present? |
| 47 | + |
| 48 | + Parsers::SepCsv::MAPPING.each do |key, value| |
| 49 | + metadata_value = extra[value] |
| 50 | + next if metadata_value.blank? |
| 51 | + |
| 52 | + csv << ["meta", nil, nil, nil, nil, nil, nil, nil, nil, key, metadata_value, "text"] |
| 53 | + end |
| 54 | + |
| 55 | + csv << ["meta", nil, nil, nil, nil, nil, nil, nil, nil, "Attribution", "Visualizer", nil] |
| 56 | + csv << ["meta", nil, nil, nil, nil, nil, nil, nil, nil, "Software", "Visualizer", nil] |
| 57 | + csv << ["meta", nil, nil, nil, nil, nil, nil, nil, nil, "Url", "https://visualizer.coffee/shots/#{shot.id}", nil] |
| 58 | + csv << ["meta", nil, nil, nil, nil, nil, nil, nil, nil, "Export version", "1.0.0", nil] |
| 59 | + |
| 60 | + timeframe.each.with_index do |time, i| |
| 61 | + csv << ["moment", time, data.dig("espresso_pressure", i), data.dig("espresso_weight", i), data.dig("espresso_flow", i), data.dig("espresso_flow_weight", i), nil, data.dig("espresso_temperature_mix", i), data.dig("espresso_temperature_basket", i), nil, nil, "Visualizer"] |
| 62 | + end |
| 63 | + end |
| 64 | + end |
38 | 65 | end
|
0 commit comments