summaryrefslogtreecommitdiff
path: root/lib/lsg_web/templates/alcoolog/user.html.eex
blob: 8907f9a4169119321d34c702eb52ef72427f4c12 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<%= if @stats.active > 0 do %>
  <h3 class="text-gray-900 text-xl leading-5 font-semibold truncate">
    <% rising_class = if @stats.rising, do: "teal", else: "red" %>
    <span class="flex-shrink-0 inline-block px-3 py-3 text-<%= rising_class %>-800 text-2xl leading-4 font-medium bg-<%= rising_class %>-100 rounded-full">
      <%= @stats.trend_symbol %> <%= Float.round(@stats.active, 4) %> g/l
    </span>

    <span class="px-3"><%= @stats.last_cl %>cl @ <%= @stats.last_deg %>°</span>

    <span class="px-3 text-lg text-gray-700"><%= if @stats.last_descr && @stats.last_descr != "" do %>
      <%= @stats.last_descr %>
    <% end %>
    </span>

    <span class="px-3 text-gray-500 text-sm font-thin"><%= LSGWeb.LayoutView.format_time(@stats.last_at) %></span>

    </h3>

    <p class="text-gray-500 font-thin text-lg">
      a commencé il y a <span class="text-gray-700 font-semibold"><%= @stats.since_s %></span>
      &mdash;
      sobre dans <span class="text-gray-700 font-semibold"><%= @stats.sober_in_s %></span>
    </p>
<% else %>
  <h3 class="text-gray-900 text-xl leading-5 font-semibold truncate">
    est sobre!

    <p class="text-gray-500 font-thin text-lg">
    dernier verre
    <span class="px-3"><%= @stats.last_cl %>cl @ <%= @stats.last_deg %>°</span>

    <span class="px-3 text-lg text-gray-700"><%= if @stats.last_descr && @stats.last_descr != "" do %>
      <%= @stats.last_descr %>
    <% end %>
    </span>

    <span class="px-3 text-gray-500 text-sm font-thin"><%= LSGWeb.LayoutView.format_time(@stats.last_at) %></span>
  </h3>
<% end %>

<canvas id="myChart" class="w-full" height="200"></canvas>
<canvas id="myChartGl" class="w-full" height="200"></canvas>


<h2 class="leading-8 m-4 font-semibold text-2xl">Historique</h2>
<div class="flex flex-col">
  <div class="-my-2 py-2 overflow-x-auto sm:-mx-6 sm:px-6 lg:-mx-8 lg:px-8">
    <div class="align-middle inline-block min-w-full shadow overflow-hidden sm:rounded-lg border-b border-gray-200">
      <table class="min-w-full divide-y divide-gray-200">
        <thead>
          <tr>
            <th class="px-6 py-3 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
              date
            </th>
            <th class="px-6 py-3 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
              &nbsp;
            </th>
            <th class="px-6 py-3 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
              &nbsp;
            </th>
          </tr>
        </thead>
        <tbody>
          <%= for {%{at: date, cl: cl, deg: deg, description: comment}, index} <- Enum.with_index(@history) do %>
            <% class = if(Integer.is_even(index), do: "bg-gray-50", else: "bg-white") %>
            <tr class="<%= class %>">
              <td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 font-medium text-gray-900">
                <%= LSGWeb.LayoutView.format_time(date, false) %>
              </td>
              <td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500"><%= cl %>cl <%= deg %>°</td>
              <td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500"><%= comment||"" %></td>
            </tr>
          <% end %>
        </tbody>
      </table>
    </div>
  </div>
</div>

<div id="metrics-gl" class="w-full"></div>

<link href='/css/metricsgraphics.css' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.css" integrity="sha512-SUJFImtiT87gVCOXl3aGC00zfDl6ggYAw5+oheJvRJ8KBXZrr/TMISSdVJ5bBarbQDRC2pR5Kto3xTR0kpZInA==" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js" integrity="sha512-vBmx0N/uQOXznm/Nbkp7h0P1RfLSj0HQrFSzV8m7rOGyj30fYAOKHYvCNez+yM8IrfnW0TCodDEjRqf6fodf/Q==" crossorigin="anonymous"></script>
<script src="/js/jquery3.1.0.min.js"></script>
<script src="/js/d3.v4.min.js"></script>
<script src="/js/metricsgraphics.min.js"></script>
    <script type="text/javascript">
  (function() {
var ctx = document.getElementById('myChart').getContext('2d');
    d3.json('<%= alcoolog_path(@conn, :nick_volumes_json, @network, @nick, days: @days) %>', function(data) {
var myChart = new Chart(ctx, {
    type: 'bar',
    data: {
      labels: data.map(function(data) { return new Date(data.date) }),
        datasets: [{
            label: 'Volumes d\'alcool',
          data: data.map(function(data) { return data.volumes }),
            borderWidth: 1
        }]
    },
    options: {
      scales: {
        xAxes: [{
          type: 'time',
          time: {
            unit: 'day'
          }
        }],
            yAxes: [{
                ticks: {
                    beginAtZero: true
                }
            }]
        }
    }
});
});




var ctxgl = document.getElementById('myChartGl').getContext('2d');
    d3.json('<%= alcoolog_path(@conn, :nick_gls_json, @network, @nick, days: @days) %>', function(data) {
var myChartgl = new Chart(ctxgl, {
    type: 'bar',
    data: {
      labels: data.map(function(data) { return new Date(data.date) }),
        datasets: [{
            label: 'g/l ingérés',
          data: data.map(function(data) { return data.gls }),
            borderWidth: 1
        }]
    },
    options: {
      scales: {
        xAxes: [{
          type: 'time',
          time: {
            unit: 'day'
          }
        }],
            yAxes: [{
                ticks: {
                    beginAtZero: true
                }
            }]
        }
    }
});
});


    d3.json('<%= alcoolog_path(@conn, :nick_log_json, @network, @nick, days: @days) %>', function(data) {
    data = data.map(function(d) {
      date = new Date(d.at);
      return {"date": date, "active": d.active};
    });
    MG.data_graphic({
        title: "g/l, All Time",
        data: data,
        width: 1000,
        height: 400,
        target: document.getElementById('metrics-gl'),
        x_accessor: 'date',
        y_accessor: 'active',
    });
  });
})();
</script>