-module(lap). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([start_with_time/3, start/2, start_in_microseconds/1, start_in_milliseconds/1, start_in_seconds/1, start_in_minutes/1, time_with_time/3, time/2, total_time/1, sort_max/1, to_list/1, pretty_print/1]). -export_type([lap_data/0, duration_data/0]). -opaque lap_data() :: {lap_data, binary(), birl:time(), birl:time(), birl@duration:unit(), list(duration_data())}. -opaque duration_data() :: {duration_data, binary(), binary(), integer()}. -file("/Users/josephlyons/Projects/Personal/gleam/lap/src/lap.gleam", 60). -spec start_with_time(binary(), birl@duration:unit(), birl:time()) -> lap_data(). start_with_time(Marker, Duration_unit, Time) -> {lap_data, Marker, Time, Time, Duration_unit, []}. -file("/Users/josephlyons/Projects/Personal/gleam/lap/src/lap.gleam", 51). -spec start(binary(), birl@duration:unit()) -> lap_data(). start(Marker, Duration_unit) -> gleam@list:repeat(birl:now(), 3), start_with_time(Marker, Duration_unit, birl:now()). -file("/Users/josephlyons/Projects/Personal/gleam/lap/src/lap.gleam", 27). -spec start_in_microseconds(binary()) -> lap_data(). start_in_microseconds(Marker) -> start(Marker, micro_second). -file("/Users/josephlyons/Projects/Personal/gleam/lap/src/lap.gleam", 33). -spec start_in_milliseconds(binary()) -> lap_data(). start_in_milliseconds(Marker) -> start(Marker, milli_second). -file("/Users/josephlyons/Projects/Personal/gleam/lap/src/lap.gleam", 39). -spec start_in_seconds(binary()) -> lap_data(). start_in_seconds(Marker) -> start(Marker, second). -file("/Users/josephlyons/Projects/Personal/gleam/lap/src/lap.gleam", 45). -spec start_in_minutes(binary()) -> lap_data(). start_in_minutes(Marker) -> start(Marker, minute). -file("/Users/josephlyons/Projects/Personal/gleam/lap/src/lap.gleam", 80). -spec time_with_time(lap_data(), binary(), birl:time()) -> lap_data(). time_with_time(Data, Marker, Time) -> {Start_marker, End_marker} = case erlang:element(6, Data) of [] -> {erlang:element(2, Data), Marker}; [Previous_duration | _] -> {erlang:element(3, Previous_duration), Marker} end, erlang:setelement( 6, erlang:setelement(4, Data, Time), [{duration_data, Start_marker, End_marker, begin _pipe = birl:difference(Time, erlang:element(4, Data)), birl@duration:blur_to(_pipe, erlang:element(5, Data)) end} | erlang:element(6, Data)] ). -file("/Users/josephlyons/Projects/Personal/gleam/lap/src/lap.gleam", 75). -spec time(lap_data(), binary()) -> lap_data(). time(Data, Marker) -> time_with_time(Data, Marker, birl:now()). -file("/Users/josephlyons/Projects/Personal/gleam/lap/src/lap.gleam", 103). -spec total_time(lap_data()) -> integer(). total_time(Data) -> _pipe = erlang:element(4, Data), _pipe@1 = birl:difference(_pipe, erlang:element(3, Data)), birl@duration:blur_to(_pipe@1, erlang:element(5, Data)). -file("/Users/josephlyons/Projects/Personal/gleam/lap/src/lap.gleam", 111). -spec sort_max(lap_data()) -> lap_data(). sort_max(Data) -> Durations = begin _pipe = erlang:element(6, Data), gleam@list:sort( _pipe, fun(A, B) -> gleam@int:compare(erlang:element(4, A), erlang:element(4, B)) end ) end, erlang:setelement(6, Data, Durations). -file("/Users/josephlyons/Projects/Personal/gleam/lap/src/lap.gleam", 125). -spec to_list(lap_data()) -> list({binary(), binary(), integer()}). to_list(Data) -> _pipe = erlang:element(6, Data), _pipe@1 = gleam@list:map( _pipe, fun(Duration) -> {erlang:element(2, Duration), erlang:element(3, Duration), erlang:element(4, Duration)} end ), lists:reverse(_pipe@1). -file("/Users/josephlyons/Projects/Personal/gleam/lap/src/lap.gleam", 163). -spec duration_unit_label(birl@duration:unit()) -> binary(). duration_unit_label(Duration_unit) -> case Duration_unit of micro_second -> <<"μs"/utf8>>; milli_second -> <<"ms"/utf8>>; second -> <<"s"/utf8>>; minute -> <<"min"/utf8>>; hour -> <<"h"/utf8>>; day -> <<"d"/utf8>>; week -> <<"w"/utf8>>; month -> <<"mo"/utf8>>; year -> <<"y"/utf8>> end. -file("/Users/josephlyons/Projects/Personal/gleam/lap/src/lap.gleam", 177). -spec to_percentage(integer(), integer()) -> float(). to_percentage(A, B) -> Ratio = case erlang:float(B) of +0.0 -> +0.0; -0.0 -> -0.0; Gleam@denominator -> erlang:float(A) / Gleam@denominator end, Ratio * 100.0. -file("/Users/josephlyons/Projects/Personal/gleam/lap/src/lap.gleam", 182). -spec to_rounded_percentage(integer(), integer()) -> float(). to_rounded_percentage(A, B) -> Percentage = to_percentage(A, B), begin _pipe@1 = begin _pipe = (Percentage * 100.0), erlang:trunc(_pipe) end, erlang:float(_pipe@1) end / 100.0. -file("/Users/josephlyons/Projects/Personal/gleam/lap/src/lap.gleam", 135). -spec pretty_print(lap_data()) -> binary(). pretty_print(Data) -> Duration_unit_label = duration_unit_label(erlang:element(5, Data)), Builder = begin _pipe = tobble:builder(), tobble:add_row( _pipe, [<<"Start"/utf8>>, <<"End"/utf8>>, <<"Duration"/utf8>>, <<"%"/utf8>>] ) end, Total_time = total_time(Data), Builder@2 = begin _pipe@1 = Data, _pipe@2 = to_list(_pipe@1), gleam@list:fold( _pipe@2, Builder, fun(Builder@1, Duration) -> _pipe@3 = Builder@1, tobble:add_row( _pipe@3, [erlang:element(1, Duration), erlang:element(2, Duration), <<<<(begin _pipe@4 = erlang:element(3, Duration), erlang:integer_to_binary(_pipe@4) end)/binary, " "/utf8>>/binary, Duration_unit_label/binary>>, begin _pipe@5 = to_rounded_percentage( erlang:element(3, Duration), Total_time ), gleam_stdlib:float_to_string(_pipe@5) end] ) end ) end, case tobble:build(Builder@2) of {ok, Table} -> _pipe@6 = Table, tobble:render(_pipe@6); {error, _} -> <<""/utf8>> end.