Created
March 6, 2018 07:01
-
-
Save gergely-marko/70b16f14445d49e928adea49c3eb5dac to your computer and use it in GitHub Desktop.
A custom report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DensityReport exposing (generate_investigation_report, generate_measurement_report) | |
import Density exposing (Density) | |
import Dict exposing (Dict) | |
import DiscThickness exposing (DiscThickness) | |
import Helpers exposing (format_float) | |
import Html.String as Html exposing (Html, b, br, div, h1, h2, h3, i, img, sub, sup, table, td, text, th, tr) | |
import Html.String.Attributes exposing (..) | |
import LayerThickness exposing (LayerThickness) | |
import Location exposing (Location) | |
import Position exposing (Position) | |
import Project exposing (Project) | |
import Record exposing (Record) | |
import Report | |
import Sample exposing (CoreSample) | |
import Set exposing (Set) | |
type alias Input = | |
{ project : Project | |
, location : Location | |
, position : Position | |
, sample : CoreSample | |
, samples : Dict String CoreSample | |
, layer_thickness : LayerThickness | |
, disc_thickness : DiscThickness | |
, density : Density | |
} | |
generate_measurement_report : Project -> Density -> Maybe String | |
generate_measurement_report project density = | |
generate_report project density measurement_report | |
generate_investigation_report : Project -> Density -> Maybe String | |
generate_investigation_report project density = | |
generate_report project density investigation_report | |
generate_report : Project -> Density -> (Input -> Html msg) -> Maybe String | |
generate_report project density generator = | |
report_input project density | |
|> Maybe.map generator | |
|> Maybe.map (Html.toString 0) | |
report_input : Project -> Density -> Maybe Input | |
report_input project density = | |
let | |
m_disc_thickness = | |
project.records | |
|> Record.get_disc_thickness density.disc_thickness_id | |
m_layer_thickness = | |
m_disc_thickness | |
|> Maybe.andThen | |
(\disc_thickness -> | |
project.records | |
|> Record.get_layer_thickness disc_thickness.layer_thickness_id | |
) | |
m_location_position_samples = | |
m_layer_thickness | |
|> Maybe.andThen | |
(\layer_thickness -> | |
Project.location_position_core_samples_of_layer_thickness project layer_thickness | |
) | |
m_sample = | |
m_location_position_samples | |
|> Maybe.andThen (\( l, p, samples ) -> samples |> Dict.values |> List.head) | |
in | |
Maybe.map4 | |
(\disc_thickness layer_thickness ( location, position, samples ) sample -> | |
Input project location position sample samples layer_thickness disc_thickness density | |
) | |
m_disc_thickness | |
m_layer_thickness | |
m_location_position_samples | |
m_sample | |
measurement_report : Input -> Html msg | |
measurement_report input = | |
let | |
layer_ids = | |
input.density.measurements | |
|> Dict.keys | |
|> List.map (String.right 1) | |
|> Set.fromList | |
|> Set.toList | |
page_count = | |
List.length layer_ids | |
in | |
layer_ids | |
|> List.indexedMap | |
(\page_index layer_id -> | |
measurement_page input layer_id page_index page_count | |
) | |
|> (\content -> | |
Html.div | |
[] | |
content | |
) | |
investigation_report : Input -> Html msg | |
investigation_report input = | |
let | |
layer_ids = | |
input.density.reported_measurements | |
|> List.filterMap | |
(\group -> | |
case group.samples of | |
[] -> | |
Nothing | |
_ -> | |
Just group.layer | |
) | |
page_count = | |
List.length layer_ids | |
in | |
layer_ids | |
|> List.indexedMap | |
(\page_index layer_id -> | |
investigation_page input layer_id page_index page_count | |
) | |
|> (\content -> | |
Html.div | |
[] | |
content | |
) | |
layer_info : Input -> String -> Maybe ( String, String ) | |
layer_info input layer_id = | |
layer_id | |
|> (String.toInt >> Result.toMaybe) | |
|> Maybe.andThen | |
(\layer_index -> | |
input.layer_thickness.layers | |
|> List.indexedMap (,) | |
|> Helpers.find (\( idx, layer ) -> idx == layer_index - 1) | |
|> Maybe.map (\( idx, layer ) -> ( layer_id, layer.description )) | |
) | |
measurement_page : Input -> String -> Int -> Int -> Html msg | |
measurement_page input layer_id page_index page_count = | |
Report.page | |
[ Report.header | |
, Report.measurement_header input.project input.location input.position input.sample (layer_info input layer_id) | |
, measurement_title | |
, measurements input layer_id | |
, Report.comment_block input.density.comment | |
, Report.measurement_footer input.density.measured_at input.density.measured_by input.density.verified_by (page_index + 1) page_count | |
] | |
investigation_page : Input -> String -> Int -> Int -> Html msg | |
investigation_page input layer_id page_index page_count = | |
Report.page | |
[ Report.header | |
, Report.investigation_header input.project input.location input.position input.sample input.density.report_index (layer_info input layer_id) | |
, measurement_title | |
, investigation_data input layer_id | |
, Report.comment_block input.density.comment | |
, Report.investigation_footer input.density.measured_at input.density.measured_by input.project.header.leader (page_index + 1) page_count | |
] | |
type alias DiscData = | |
{ code : String | |
, measurement : Density.Measurement | |
, diameter : Int | |
, thickness : Float | |
} | |
measurements : Input -> String -> Html msg | |
measurements input layer_id = | |
let | |
disc_data : List DiscData | |
disc_data = | |
input.density.measurements | |
|> Dict.toList | |
|> List.filterMap | |
(\( code, measurement ) -> | |
if String.right 1 code == layer_id then | |
input.samples | |
|> Dict.get (String.left 3 code) | |
|> Maybe.andThen | |
(\sample -> | |
input.disc_thickness.measurements | |
|> Dict.get code | |
|> Maybe.map | |
(\m -> | |
{ code = code | |
, measurement = measurement | |
, diameter = sample.diameter | |
, thickness = (m.h1 + m.h2 + m.h3 + m.h4) / 4 | |
} | |
) | |
) | |
else | |
Nothing | |
) | |
in | |
table | |
[ class "strong-border" ] | |
(List.concat | |
[ Report.first_row disc_data "A próbatest jele" | |
, Report.eq_rows disc_data | |
"Átmérő" | |
[ text "d" ] | |
"[mm]" | |
(\data -> data.diameter |> toFloat |> format_float 1 |> text) | |
"" | |
, Report.eq_rows disc_data | |
"Magasság" | |
[ text "h" ] | |
"[mm]" | |
(\data -> text <| format_float 1 data.thickness) | |
"" | |
, Report.eq_rows disc_data | |
"Próbatest tömege levegőn" | |
[ text "m", sub [] [ text "1" ] ] | |
"[g]" | |
(\data -> text <| format_float 1 data.measurement.m1) | |
"" | |
, Report.eq_rows disc_data | |
"Próbatest tömege víz alatt" | |
[ text "m", sub [] [ text "2" ] ] | |
"[g]" | |
(\data -> text <| format_float 1 data.measurement.m2) | |
"" | |
, Report.eq_rows disc_data | |
"Telített, száraz felületű próbatest tömege" | |
[ text "m", sub [] [ text "3" ] ] | |
"[g]" | |
(\data -> text <| format_float 1 data.measurement.m3) | |
"" | |
, Report.eq_rows disc_data | |
"A víz hőmérséklete" | |
[ text "T" ] | |
"[°C]" | |
(\data -> text <| format_float 1 data.measurement.t_water) | |
"" | |
, Report.eq_rows disc_data | |
"A víz sűrűsége" | |
[ text "ρ", sub [] [ text "v" ] ] | |
"[kg/m³]" | |
(\data -> Helpers.density_of_water data.measurement.t_water * 1000 |> format_float 1 |> text) | |
"" | |
, Report.eq_rows disc_data | |
"Testsűrűség" | |
[ text "ρ", sub [] [ text "t,SSD" ], text " = ρ", sub [] [ text "v" ], text " × m", sub [] [ text "1" ], text " / (m", sub [] [ text "3" ], text " - m", sub [] [ text "2" ], text ")" ] | |
"[Mg/m³]" | |
(\data -> Density.density data.measurement |> format_float 3 |> text) | |
(if List.length disc_data == 1 then | |
"bold" | |
else | |
"" | |
) | |
, let | |
measurements = | |
List.map .measurement disc_data | |
densities = | |
List.map Density.density measurements | |
in | |
densities | |
|> Helpers.common_result | |
|> Maybe.map | |
(\result -> | |
List.concat | |
[ Report.sum_row disc_data | |
"Testsűrűségek átlaga" | |
[ text "ρ", sub [] [ text "t,SSD átlag" ] ] | |
"[Mg/m³]" | |
(result.average |> format_float 3 |> text) | |
"bold" | |
, Report.sum_row disc_data | |
"Megengedett terjedelem" | |
[ text "2,77 × σ", sub [] [ text "r" ], text " ; σ", sub [] [ text "r" ], text " = (6 + 0,01 × A) / 1000" ] | |
"[Mg/m³]" | |
(result.allowed_range |> format_float 3 |> text) | |
"" | |
, Report.sum_row disc_data | |
"A mérési értékek terjedelme" | |
[] | |
"[Mg/m³]" | |
(result.range |> format_float 3 |> text) | |
"" | |
, [ tr [] | |
[ th | |
[ colspan (3 + List.length disc_data) ] | |
[ text result.is_range_accepted_measurement ] | |
] | |
] | |
] | |
) | |
|> Maybe.withDefault [] | |
] | |
) | |
investigation_data : Input -> String -> Html msg | |
investigation_data input layer_id = | |
let | |
disc_data : List DiscData | |
disc_data = | |
input.density.reported_measurements | |
|> Helpers.findMap | |
(\group -> | |
if group.layer == layer_id then | |
Just group.samples | |
else | |
Nothing | |
) | |
|> Maybe.map | |
(\sample_codes -> | |
sample_codes | |
|> List.filterMap | |
(\sample_code -> | |
input.density.measurements | |
|> Dict.get (sample_code ++ layer_id) | |
|> Maybe.andThen | |
(\measurement -> | |
input.samples | |
|> Dict.get sample_code | |
|> Maybe.andThen | |
(\sample -> | |
input.disc_thickness.measurements | |
|> Dict.get (sample_code ++ layer_id) | |
|> Maybe.map | |
(\m -> | |
{ code = sample_code ++ layer_id | |
, measurement = measurement | |
, diameter = sample.diameter | |
, thickness = (m.h1 + m.h2 + m.h3 + m.h4) / 4 | |
} | |
) | |
) | |
) | |
) | |
) | |
|> Maybe.withDefault [] | |
in | |
table | |
[ class "strong-border" ] | |
(List.concat | |
[ Report.first_row disc_data "A próbatest jele" | |
, Report.eq_rows disc_data | |
"Átmérő" | |
[ text "d" ] | |
"[mm]" | |
(\data -> data.diameter |> toFloat |> format_float 1 |> text) | |
"" | |
, Report.eq_rows disc_data | |
"Magasság" | |
[ text "h" ] | |
"[mm]" | |
(\data -> text <| format_float 1 data.thickness) | |
"" | |
, Report.eq_rows disc_data | |
"Próbatest tömege levegőn" | |
[ text "m", sub [] [ text "1" ] ] | |
"[g]" | |
(\data -> text <| format_float 1 data.measurement.m1) | |
"" | |
, Report.eq_rows disc_data | |
"Testsűrűség" | |
[ text "ρ", sub [] [ text "t,SSD" ] ] | |
"[Mg/m³]" | |
(\data -> Density.density data.measurement |> format_float 3 |> text) | |
(if List.length disc_data == 1 then | |
"bold" | |
else | |
"" | |
) | |
, let | |
measurements = | |
List.map .measurement disc_data | |
densities = | |
List.map Density.density measurements | |
in | |
densities | |
|> Helpers.common_result | |
|> Maybe.map | |
(\result -> | |
List.concat | |
[ Report.sum_row disc_data | |
"Testsűrűségek átlaga" | |
[ text "ρ", sub [] [ text "t,SSD átlag" ] ] | |
"[Mg/m³]" | |
(result.average |> format_float 3 |> text) | |
"bold" | |
, Report.sum_row disc_data | |
"Megengedett terjedelem" | |
[] | |
"[Mg/m³]" | |
(result.allowed_range |> format_float 3 |> text) | |
"" | |
, Report.sum_row disc_data | |
"A mérési értékek terjedelme" | |
[] | |
"[Mg/m³]" | |
(result.range |> format_float 3 |> text) | |
"" | |
, [ tr [] | |
[ th | |
[ colspan (3 + List.length disc_data) ] | |
[ text result.is_range_accepted_measurement ] | |
] | |
] | |
] | |
) | |
|> Maybe.withDefault [] | |
] | |
) | |
measurement_title : Html msg | |
measurement_title = | |
Report.measurement_title | |
[ "Aszfaltkeverékek. Meleg aszfaltkeverékek vizsgálati módszerei." | |
, "6. rész: Aszfalt próbatestek testűrűségének meghatározása." | |
, "MSZ EN 12697-6:2012 9.3.B eljárás (A085)" | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment