friction_loss.outputs.webreport_utils

  1import pathlib
  2from datetime import datetime
  3from typing import Dict, Union
  4
  5import numpy as np
  6import plotly.graph_objects as go
  7from custom_plugin_base.utils.service_enum import LangEnum
  8from polydoc.polypage import polypage
  9
 10from friction_loss.utils.plugin_dataclasses import PolypresInputParameter, ProjectInfo
 11from friction_loss.utils.plugin_dataclasses import TransientData
 12from friction_loss.utils.set_language import (PARAMETERS_NAMES_TRANSLATOR, NAMES_COLUMNS_TRANSLATOR, TITLE_PAGE_NAMES,
 13                                              CONVERT_UNITS, PAGES_NAMES_TRANSLATOR)
 14
 15
 16def create_table_params(page: polypage, data_dict: Dict[str, PolypresInputParameter], language: LangEnum) -> None:
 17    """
 18    The function of creating a table with well parameters on a page in a web-report.
 19
 20    Parameters
 21    ----------
 22    page: polypage
 23        Web-report page.
 24    data_dict: dict[str, PolypresInputParameter]
 25        keys: parameter names
 26        values: dataclass with rows of table in initial units.
 27    language: LangEnum
 28        Language of interface.
 29    """
 30
 31    name = [NAMES_COLUMNS_TRANSLATOR[language]['name']] + [PARAMETERS_NAMES_TRANSLATOR[language][item.name] for item in
 32                                                           data_dict.values()][:-1]
 33    values = [item.value for item in data_dict.values()][:-1]  # [:-1] чтобы не выводить строку флага генерации веб-отчета
 34    units = [item.unit for item in data_dict.values()][:-1]
 35
 36    value = [NAMES_COLUMNS_TRANSLATOR[language]['val']] + ['-' if (str(item) == 'nan' or str(item) == 'None') else item for item in values]
 37    value = [round(item, 3) if ((type(item) is not str) and (item > 1e-2)) else item for item in value]
 38    value[-2] = round(value[-2], 6)
 39    unit = [NAMES_COLUMNS_TRANSLATOR[language]['unit']] + ['-' if isinstance(item, (int, float)) else item for item in units]
 40    if language == LangEnum.RU:
 41        unit = [CONVERT_UNITS[i] if i in CONVERT_UNITS.keys() else i for i in unit]
 42
 43    table_style = dict(pl=0.5, b='s1', fc='black')
 44
 45    cells = ', '.join(f'({i+1}, *)' for i in range(0, len(name), 2))
 46    cell_style = {'(1,*)': dict(fw='bold', b='b2'),
 47                  f'({cells})': dict(fc='black', b='s1', bc='ws')}
 48
 49    page.add_table(page.hold, data=[*map(list, zip(name, value, unit))], table_style=table_style, cell_style=cell_style,
 50                   margin_left=3, width=70, height=40, border='gr2')
 51
 52
 53def create_title_table(page: polypage, info: ProjectInfo, language: LangEnum) -> None:
 54    """
 55    The function of creating a table with project info on title page in a web-report.
 56
 57    Parameters
 58    ----------
 59    page: polypage
 60        Web-report page.
 61    info: ProjectInfo
 62        Dataclass with project data.
 63    language: LangEnum
 64        Language of interface.
 65    """
 66    if language == LangEnum.US:
 67        name = TITLE_PAGE_NAMES.keys()
 68    else:
 69        name = TITLE_PAGE_NAMES.values()
 70
 71    today = datetime.now().strftime("%d.%m.%Y")
 72    if info.info_date != '':
 73        info_data = datetime.strptime(info.info_date, "%Y-%m-%d").strftime("%d.%m.%Y")
 74    else:
 75        info_data = ''
 76
 77    value = [info.project_name, info.id, info_data, today, info.company, f'{info.field} ({info.country})', info.contractor,
 78             f'{info.curator} ({info.curator_email})', f'{info.analyst} ({info.analyst_email})', info.well_name]
 79    value = ['-' if i.replace('()', '') in ['', ' '] else i.replace('()', '') for i in value]
 80    table_style = dict(pl=0.5, b='s1', fc='black')
 81
 82    # заливка нечетных строк белым цветом (так легче ориентрироваться по строкам)
 83    cells = ', '.join(f'({i}, *)' for i in range(1, len(name), 2))
 84    cell_style = {f'({cells})': dict(fc='black', b='s1', bc='ws')}
 85
 86    page.add_table(page.hold, data=[*map(list, zip(name, value))], table_style=table_style, cell_style=cell_style,
 87                   margin_left=3, width=70, height=30, border='gr2')
 88
 89
 90def create_plot(path: pathlib.Path, name: str, page: polypage, x: np.ndarray, y: dict, x_label: str,
 91                y_label: str, x_unit: str, y_unit: str, language: LangEnum, idx: int,
 92                well_name: str, depths: Dict[str, Dict], depth_unit: str) -> None:
 93    """
 94    Generate plot.
 95
 96    Parameters
 97    ----------
 98    path: pathlib.Path
 99        Full path to the folder that is sent to the user as an archive.
100    name: str
101        Chart title (same as the title of the pages web-report)
102    page: polypage
103        Web-report page.
104    x: np.ndarray
105        X-axis values.
106    y: dict
107        Y-axis values.
108    x_label: str
109        X-axis name.
110    y_label: str
111        Y-axis name.
112    x_unit: str
113        X-axis units.
114    y_unit: str
115        Y-axis units.
116    language: LangEnum
117        Selected interface language.
118    idx: int
119        Well number.
120    well_name: str
121        Name of well
122    depths: Dict[str, Dict]
123        Dictionary with referenced depth and gauge depth
124    """
125
126    fig = go.Figure()
127    diff_pres = np.array(y['depth'][idx] - y['initial'][idx], dtype=float)
128    ref_name = f'{PAGES_NAMES_TRANSLATOR[language]["depth"]} - {depths["ref"]}, {depth_unit}'
129    gauge_name = f'{PAGES_NAMES_TRANSLATOR[language]["depth"]} - {depths["gauge"]}, {depth_unit}'
130    fig.add_trace(go.Scatter(x=x, y=y['initial'][idx], name=gauge_name,
131                             mode='markers', marker=dict(color='blue', size=9),
132                             customdata=np.round(diff_pres, 5)))
133    fig.add_trace(go.Scatter(x=x, y=y['depth'][idx], name=ref_name,
134                             mode='markers', marker=dict(color='red', size=9),
135                             customdata=np.round(diff_pres, 5)))
136    fig.update_layout(hovermode="x", hoverlabel=dict(bgcolor="white"))
137
138    # Добавили подсказки
139    fig.update_traces(hoverinfo='all',
140                      hovertemplate='<br>'.join([f'{PAGES_NAMES_TRANSLATOR[language]["time"]}' + ': %{x} ' + x_unit,
141                                                 f'{PAGES_NAMES_TRANSLATOR[language]["pressure"]}' + ': %{y} ' + y_unit,
142                                                 PAGES_NAMES_TRANSLATOR[language]['p_drop'] + ': %{customdata} ' +
143                                                 y_unit]) + '<extra></extra>')
144
145    # Добавили настройки графика
146    fig = _set_graph_properties(fig, x_label, y_label, x_unit, y_unit, False)
147
148    fig.write_image(file=path.parent.parent / f'{name}_{well_name}.svg', width=1350, height=750)
149    fig.write_html(file=path.parent.parent / f'{name}_{well_name}.html', include_plotlyjs=path / 'js' / 'plotly_script.js')
150
151    page.copy_file(path.parent.parent / f'{name}_{well_name}.html',
152                   str(path) + f"/{PAGES_NAMES_TRANSLATOR[language]['report']}/{well_name}/" + page.title + '/img')
153    page.copy_file(path.parent.parent / f'{name}_{well_name}.svg',
154                   str(path) + f"/{PAGES_NAMES_TRANSLATOR[language]['report']}/{well_name}/" + page.title + '/img')
155
156    page.add_figure(classname='pkd_base', width='100%', src='img/' + f'{name}_{well_name}.svg',
157                    href='img/' + f'{name}_{well_name}.html', ref='live_plot', title=name,
158                    number=1, title_separator='&#32; &#8212; &#32;',
159                    title_tag=page.locale[language.value]['Fig.'])
160
161
162def create_animate_plot(path: pathlib.Path, name: str, page: polypage, data: TransientData,
163                        time: Dict[str, Union[np.ndarray, str]], x_label: str, y_label: str,
164                        x_unit: str, y_unit: str, language: LangEnum, idx: int, well_name: str) -> None:
165    """
166    Generate animate plot.
167
168    Parameters
169    ----------
170    path: pathlib.Path
171        Full path to the folder that is sent to the user as an archive.
172    name: str
173        Chart title (same as the title of the pages web-report)
174    page: polypage
175        Web-report page.
176    data: np.ndarray
177        X-axis values.
178    time: dict[str, np.ndarray | str]
179        'unit': Time units.
180        'value': Time points array.
181    x_label: str
182        X-axis name.
183    y_label: str
184        Y-axis name.
185    x_unit: str
186        X-axis units.
187    y_unit: str
188        Y-axis units.
189    language: LangEnum
190        Selected interface language.
191    idx: int
192        Well number.
193    well_name: str
194        Name of well.
195    """
196    n_points = data.pressure[1].shape[0]
197    n_times = data.pressure[1][0].shape[0]
198    trace_list = [go.Scatter(visible=False, x=data.pressure[1][i], y=data.pressure[0], mode='lines',
199                             marker=dict(color='blue', line=dict(width=9)),
200                             customdata=[[f'{round(data.qo[i], 3)} {data.qo_unit}',
201                                          f'{round(data.qw[i], 3)} {data.qw_unit}',
202                                          f'{round(data.qg[i], 3)} {data.qg_unit}']]*n_points) for i in range(n_times)]
203    trace_list[0].visible = True
204    fig = go.Figure(data=trace_list)
205
206    steps = []
207    for i in range(n_times):
208        step = dict(
209            method='restyle',
210            args=['visible', [False] * len(fig.data)],
211            label=f'{round(time["value"][idx][i], 2)} {time["unit"]}',
212        )
213        step['args'][1][i] = True
214        steps.append(step)
215
216    sliders = [dict(
217        currentvalue={"prefix": f"{PAGES_NAMES_TRANSLATOR[language]['time']}: ", "font": {"size": 20}},
218        pad={"b": 10, "t": 50},
219        steps=steps,
220    )]
221
222    # Добавили настройки графика
223    fig = _set_graph_properties(fig, x_label, y_label, x_unit, y_unit, True)
224
225    # Добавили подсказки
226    fig.update_traces(hoverinfo='all', hovertemplate='<br>'.join([f'{PAGES_NAMES_TRANSLATOR[language]["depth"]}' + ': %{y} ' + y_unit,
227                                                                  f'{PAGES_NAMES_TRANSLATOR[language]["pressure"]}' + ': %{x} ' + x_unit,
228                                                                  'Qo: %{customdata[0]}',
229                                                                  'Qw: %{customdata[1]}',
230                                                                  'Qg: %{customdata[2]}'])+'<extra></extra>')
231    fig.update_layout(hoverlabel=dict(bgcolor="white"))
232
233    fig.layout.sliders = sliders
234
235    fig.write_html(file=path.parent.parent / f'{name}_{well_name}.html',
236                   include_plotlyjs=path / 'js' / 'plotly_script.js')
237
238    # Создали первую картинку интерактивного графика
239    first_img = go.Figure()
240    first_img.add_trace(go.Scatter(visible=True, x=data.pressure[1][0], y=data.pressure[0], mode='lines',
241                        marker=dict(color='blue', size=10)))
242    # Добавили настройки графика
243    first_img = _set_graph_properties(first_img, x_label, y_label, x_unit, y_unit, True)
244    first_img.write_image(file=path.parent.parent / f'{name}_{well_name}.svg', width=1350, height=750)
245
246    page.copy_file(path.parent.parent / f'{name}_{well_name}.html',
247                   str(path) + f"/{PAGES_NAMES_TRANSLATOR[language]['report']}/{well_name}/" + page.title + '/img')
248    page.copy_file(path.parent.parent / f'{name}_{well_name}.svg',
249                   str(path) + f"/{PAGES_NAMES_TRANSLATOR[language]['report']}/{well_name}/" + page.title + '/img')
250
251    page.add_figure(classname='pkd_base', width='100%', src='img/' + f'{name}_{well_name}.svg',
252                    href='img/' + f'{name}_{well_name}.html', ref='live_plot', title=name,
253                    number=2, title_separator='&#32; &#8212; &#32;',
254                    title_tag=page.locale[language.value]['Fig.'])
255
256
257def _set_graph_properties(fig: go.Figure, x_label: str, y_label: str, x_unit: str,
258                          y_unit: str, reversed_y: bool) -> go.Figure:
259    fig.update_layout(margin=dict(l=20, r=20, t=20, b=0),
260                      autosize=True,
261                      xaxis_title=f"{x_label}, {x_unit}",
262                      yaxis_title=f"{y_label}, {y_unit}",
263                      paper_bgcolor="rgba(0, 0, 0, 0)",
264                      plot_bgcolor="rgb(255, 255, 255)",
265                      legend_orientation="h",
266                      legend=dict(x=.5, xanchor="center", font=dict(size=22)),
267                      uniformtext_minsize=24)
268
269    if reversed_y:
270        # Перевернули вертикальную ось
271        fig.update_yaxes(autorange="reversed")
272
273    # Добавили рамку вокруг графика и заадли размер шрифта
274    fig.update_xaxes(showline=True, linecolor='black', mirror=True, title_font=dict(size=22))
275    fig.update_yaxes(showline=True, linecolor='black', mirror=True, title_font=dict(size=22))
276
277    # Добавили сетку (пунктирные линии) и оси
278    fig.update_xaxes(zeroline=True, zerolinecolor='black', gridcolor='black', griddash='dash', linewidth=1)
279    fig.update_yaxes(zeroline=True, zerolinecolor='black', gridcolor='black', griddash='dash', linewidth=1)
280
281    return fig
282
283
284# # ---Функция не используется оставил на всякий случай---
285# def create_plot_xplot(path: pathlib.Path, page: polypage, x: np.ndarray, y: np.ndarray, x_label: str, y_label: str, x_unit: str, y_unit: str) -> None:
286#     """
287#         Gererate plot.
288#     """
289#
290#     data = {'plt': {'xaxis': 'bottom',
291#                     'yaxis': 'left',
292#                     'color': 'blue',
293#                     'points': np.array([x, y])}
294#             }
295#
296#     plot_params = {
297#         'figure_format': 'svg',
298#         'width': 10,  # inches
299#         'height': 8,  # inches
300#         'axis': {
301#             'axis_bottom': {'location': 'bottom', 'title': f'{x_label}, {x_unit}', 'font_size': 14},
302#             'axis_left': {'location': 'left', 'title': f'{y_label}, {y_unit}', 'font_size': 14}
303#         }
304#     }
305#
306#     plot = xplot(data=data, chart=plot_params)
307#
308#     page.add_figure(src=plot.src, src_ext=plot.src_ext, href=plot.href, classname='pkd_base', width='65%')
def create_table_params( page: polydoc.polypage.polypage, data_dict: Dict[str, friction_loss.utils.plugin_dataclasses.PolypresInputParameter], language: custom_plugin_base.utils.service_enum.LangEnum) -> None:
17def create_table_params(page: polypage, data_dict: Dict[str, PolypresInputParameter], language: LangEnum) -> None:
18    """
19    The function of creating a table with well parameters on a page in a web-report.
20
21    Parameters
22    ----------
23    page: polypage
24        Web-report page.
25    data_dict: dict[str, PolypresInputParameter]
26        keys: parameter names
27        values: dataclass with rows of table in initial units.
28    language: LangEnum
29        Language of interface.
30    """
31
32    name = [NAMES_COLUMNS_TRANSLATOR[language]['name']] + [PARAMETERS_NAMES_TRANSLATOR[language][item.name] for item in
33                                                           data_dict.values()][:-1]
34    values = [item.value for item in data_dict.values()][:-1]  # [:-1] чтобы не выводить строку флага генерации веб-отчета
35    units = [item.unit for item in data_dict.values()][:-1]
36
37    value = [NAMES_COLUMNS_TRANSLATOR[language]['val']] + ['-' if (str(item) == 'nan' or str(item) == 'None') else item for item in values]
38    value = [round(item, 3) if ((type(item) is not str) and (item > 1e-2)) else item for item in value]
39    value[-2] = round(value[-2], 6)
40    unit = [NAMES_COLUMNS_TRANSLATOR[language]['unit']] + ['-' if isinstance(item, (int, float)) else item for item in units]
41    if language == LangEnum.RU:
42        unit = [CONVERT_UNITS[i] if i in CONVERT_UNITS.keys() else i for i in unit]
43
44    table_style = dict(pl=0.5, b='s1', fc='black')
45
46    cells = ', '.join(f'({i+1}, *)' for i in range(0, len(name), 2))
47    cell_style = {'(1,*)': dict(fw='bold', b='b2'),
48                  f'({cells})': dict(fc='black', b='s1', bc='ws')}
49
50    page.add_table(page.hold, data=[*map(list, zip(name, value, unit))], table_style=table_style, cell_style=cell_style,
51                   margin_left=3, width=70, height=40, border='gr2')

The function of creating a table with well parameters on a page in a web-report.

Parameters

page: polypage Web-report page. data_dict: dict[str, PolypresInputParameter] keys: parameter names values: dataclass with rows of table in initial units. language: LangEnum Language of interface.

def create_title_table( page: polydoc.polypage.polypage, info: friction_loss.utils.plugin_dataclasses.ProjectInfo, language: custom_plugin_base.utils.service_enum.LangEnum) -> None:
54def create_title_table(page: polypage, info: ProjectInfo, language: LangEnum) -> None:
55    """
56    The function of creating a table with project info on title page in a web-report.
57
58    Parameters
59    ----------
60    page: polypage
61        Web-report page.
62    info: ProjectInfo
63        Dataclass with project data.
64    language: LangEnum
65        Language of interface.
66    """
67    if language == LangEnum.US:
68        name = TITLE_PAGE_NAMES.keys()
69    else:
70        name = TITLE_PAGE_NAMES.values()
71
72    today = datetime.now().strftime("%d.%m.%Y")
73    if info.info_date != '':
74        info_data = datetime.strptime(info.info_date, "%Y-%m-%d").strftime("%d.%m.%Y")
75    else:
76        info_data = ''
77
78    value = [info.project_name, info.id, info_data, today, info.company, f'{info.field} ({info.country})', info.contractor,
79             f'{info.curator} ({info.curator_email})', f'{info.analyst} ({info.analyst_email})', info.well_name]
80    value = ['-' if i.replace('()', '') in ['', ' '] else i.replace('()', '') for i in value]
81    table_style = dict(pl=0.5, b='s1', fc='black')
82
83    # заливка нечетных строк белым цветом (так легче ориентрироваться по строкам)
84    cells = ', '.join(f'({i}, *)' for i in range(1, len(name), 2))
85    cell_style = {f'({cells})': dict(fc='black', b='s1', bc='ws')}
86
87    page.add_table(page.hold, data=[*map(list, zip(name, value))], table_style=table_style, cell_style=cell_style,
88                   margin_left=3, width=70, height=30, border='gr2')

The function of creating a table with project info on title page in a web-report.

Parameters

page: polypage Web-report page. info: ProjectInfo Dataclass with project data. language: LangEnum Language of interface.

def create_plot( path: pathlib.Path, name: str, page: polydoc.polypage.polypage, x: numpy.ndarray, y: dict, x_label: str, y_label: str, x_unit: str, y_unit: str, language: custom_plugin_base.utils.service_enum.LangEnum, idx: int, well_name: str, depths: Dict[str, Dict], depth_unit: str) -> None:
 91def create_plot(path: pathlib.Path, name: str, page: polypage, x: np.ndarray, y: dict, x_label: str,
 92                y_label: str, x_unit: str, y_unit: str, language: LangEnum, idx: int,
 93                well_name: str, depths: Dict[str, Dict], depth_unit: str) -> None:
 94    """
 95    Generate plot.
 96
 97    Parameters
 98    ----------
 99    path: pathlib.Path
100        Full path to the folder that is sent to the user as an archive.
101    name: str
102        Chart title (same as the title of the pages web-report)
103    page: polypage
104        Web-report page.
105    x: np.ndarray
106        X-axis values.
107    y: dict
108        Y-axis values.
109    x_label: str
110        X-axis name.
111    y_label: str
112        Y-axis name.
113    x_unit: str
114        X-axis units.
115    y_unit: str
116        Y-axis units.
117    language: LangEnum
118        Selected interface language.
119    idx: int
120        Well number.
121    well_name: str
122        Name of well
123    depths: Dict[str, Dict]
124        Dictionary with referenced depth and gauge depth
125    """
126
127    fig = go.Figure()
128    diff_pres = np.array(y['depth'][idx] - y['initial'][idx], dtype=float)
129    ref_name = f'{PAGES_NAMES_TRANSLATOR[language]["depth"]} - {depths["ref"]}, {depth_unit}'
130    gauge_name = f'{PAGES_NAMES_TRANSLATOR[language]["depth"]} - {depths["gauge"]}, {depth_unit}'
131    fig.add_trace(go.Scatter(x=x, y=y['initial'][idx], name=gauge_name,
132                             mode='markers', marker=dict(color='blue', size=9),
133                             customdata=np.round(diff_pres, 5)))
134    fig.add_trace(go.Scatter(x=x, y=y['depth'][idx], name=ref_name,
135                             mode='markers', marker=dict(color='red', size=9),
136                             customdata=np.round(diff_pres, 5)))
137    fig.update_layout(hovermode="x", hoverlabel=dict(bgcolor="white"))
138
139    # Добавили подсказки
140    fig.update_traces(hoverinfo='all',
141                      hovertemplate='<br>'.join([f'{PAGES_NAMES_TRANSLATOR[language]["time"]}' + ': %{x} ' + x_unit,
142                                                 f'{PAGES_NAMES_TRANSLATOR[language]["pressure"]}' + ': %{y} ' + y_unit,
143                                                 PAGES_NAMES_TRANSLATOR[language]['p_drop'] + ': %{customdata} ' +
144                                                 y_unit]) + '<extra></extra>')
145
146    # Добавили настройки графика
147    fig = _set_graph_properties(fig, x_label, y_label, x_unit, y_unit, False)
148
149    fig.write_image(file=path.parent.parent / f'{name}_{well_name}.svg', width=1350, height=750)
150    fig.write_html(file=path.parent.parent / f'{name}_{well_name}.html', include_plotlyjs=path / 'js' / 'plotly_script.js')
151
152    page.copy_file(path.parent.parent / f'{name}_{well_name}.html',
153                   str(path) + f"/{PAGES_NAMES_TRANSLATOR[language]['report']}/{well_name}/" + page.title + '/img')
154    page.copy_file(path.parent.parent / f'{name}_{well_name}.svg',
155                   str(path) + f"/{PAGES_NAMES_TRANSLATOR[language]['report']}/{well_name}/" + page.title + '/img')
156
157    page.add_figure(classname='pkd_base', width='100%', src='img/' + f'{name}_{well_name}.svg',
158                    href='img/' + f'{name}_{well_name}.html', ref='live_plot', title=name,
159                    number=1, title_separator='&#32; &#8212; &#32;',
160                    title_tag=page.locale[language.value]['Fig.'])

Generate plot.

Parameters

path: pathlib.Path Full path to the folder that is sent to the user as an archive. name: str Chart title (same as the title of the pages web-report) page: polypage Web-report page. x: np.ndarray X-axis values. y: dict Y-axis values. x_label: str X-axis name. y_label: str Y-axis name. x_unit: str X-axis units. y_unit: str Y-axis units. language: LangEnum Selected interface language. idx: int Well number. well_name: str Name of well depths: Dict[str, Dict] Dictionary with referenced depth and gauge depth

def create_animate_plot( path: pathlib.Path, name: str, page: polydoc.polypage.polypage, data: friction_loss.utils.plugin_dataclasses.TransientData, time: Dict[str, Union[str, numpy.ndarray]], x_label: str, y_label: str, x_unit: str, y_unit: str, language: custom_plugin_base.utils.service_enum.LangEnum, idx: int, well_name: str) -> None:
163def create_animate_plot(path: pathlib.Path, name: str, page: polypage, data: TransientData,
164                        time: Dict[str, Union[np.ndarray, str]], x_label: str, y_label: str,
165                        x_unit: str, y_unit: str, language: LangEnum, idx: int, well_name: str) -> None:
166    """
167    Generate animate plot.
168
169    Parameters
170    ----------
171    path: pathlib.Path
172        Full path to the folder that is sent to the user as an archive.
173    name: str
174        Chart title (same as the title of the pages web-report)
175    page: polypage
176        Web-report page.
177    data: np.ndarray
178        X-axis values.
179    time: dict[str, np.ndarray | str]
180        'unit': Time units.
181        'value': Time points array.
182    x_label: str
183        X-axis name.
184    y_label: str
185        Y-axis name.
186    x_unit: str
187        X-axis units.
188    y_unit: str
189        Y-axis units.
190    language: LangEnum
191        Selected interface language.
192    idx: int
193        Well number.
194    well_name: str
195        Name of well.
196    """
197    n_points = data.pressure[1].shape[0]
198    n_times = data.pressure[1][0].shape[0]
199    trace_list = [go.Scatter(visible=False, x=data.pressure[1][i], y=data.pressure[0], mode='lines',
200                             marker=dict(color='blue', line=dict(width=9)),
201                             customdata=[[f'{round(data.qo[i], 3)} {data.qo_unit}',
202                                          f'{round(data.qw[i], 3)} {data.qw_unit}',
203                                          f'{round(data.qg[i], 3)} {data.qg_unit}']]*n_points) for i in range(n_times)]
204    trace_list[0].visible = True
205    fig = go.Figure(data=trace_list)
206
207    steps = []
208    for i in range(n_times):
209        step = dict(
210            method='restyle',
211            args=['visible', [False] * len(fig.data)],
212            label=f'{round(time["value"][idx][i], 2)} {time["unit"]}',
213        )
214        step['args'][1][i] = True
215        steps.append(step)
216
217    sliders = [dict(
218        currentvalue={"prefix": f"{PAGES_NAMES_TRANSLATOR[language]['time']}: ", "font": {"size": 20}},
219        pad={"b": 10, "t": 50},
220        steps=steps,
221    )]
222
223    # Добавили настройки графика
224    fig = _set_graph_properties(fig, x_label, y_label, x_unit, y_unit, True)
225
226    # Добавили подсказки
227    fig.update_traces(hoverinfo='all', hovertemplate='<br>'.join([f'{PAGES_NAMES_TRANSLATOR[language]["depth"]}' + ': %{y} ' + y_unit,
228                                                                  f'{PAGES_NAMES_TRANSLATOR[language]["pressure"]}' + ': %{x} ' + x_unit,
229                                                                  'Qo: %{customdata[0]}',
230                                                                  'Qw: %{customdata[1]}',
231                                                                  'Qg: %{customdata[2]}'])+'<extra></extra>')
232    fig.update_layout(hoverlabel=dict(bgcolor="white"))
233
234    fig.layout.sliders = sliders
235
236    fig.write_html(file=path.parent.parent / f'{name}_{well_name}.html',
237                   include_plotlyjs=path / 'js' / 'plotly_script.js')
238
239    # Создали первую картинку интерактивного графика
240    first_img = go.Figure()
241    first_img.add_trace(go.Scatter(visible=True, x=data.pressure[1][0], y=data.pressure[0], mode='lines',
242                        marker=dict(color='blue', size=10)))
243    # Добавили настройки графика
244    first_img = _set_graph_properties(first_img, x_label, y_label, x_unit, y_unit, True)
245    first_img.write_image(file=path.parent.parent / f'{name}_{well_name}.svg', width=1350, height=750)
246
247    page.copy_file(path.parent.parent / f'{name}_{well_name}.html',
248                   str(path) + f"/{PAGES_NAMES_TRANSLATOR[language]['report']}/{well_name}/" + page.title + '/img')
249    page.copy_file(path.parent.parent / f'{name}_{well_name}.svg',
250                   str(path) + f"/{PAGES_NAMES_TRANSLATOR[language]['report']}/{well_name}/" + page.title + '/img')
251
252    page.add_figure(classname='pkd_base', width='100%', src='img/' + f'{name}_{well_name}.svg',
253                    href='img/' + f'{name}_{well_name}.html', ref='live_plot', title=name,
254                    number=2, title_separator='&#32; &#8212; &#32;',
255                    title_tag=page.locale[language.value]['Fig.'])

Generate animate plot.

Parameters

path: pathlib.Path Full path to the folder that is sent to the user as an archive. name: str Chart title (same as the title of the pages web-report) page: polypage Web-report page. data: np.ndarray X-axis values. time: dict[str, np.ndarray | str] 'unit': Time units. 'value': Time points array. x_label: str X-axis name. y_label: str Y-axis name. x_unit: str X-axis units. y_unit: str Y-axis units. language: LangEnum Selected interface language. idx: int Well number. well_name: str Name of well.