tdfs4ds.agent.historian_plot¶
tdfs4ds.agent.historian_plot
¶
PLOT skill, historian part (0.3.8.10): A versus B of two tags, charts per period, which historian.
Read by code, never guessed. Three kinds of request reach :func:handle:
- Tag A versus tag B ("plot
vs using ", "trace en fonction de "): both tags resolved against the historian's documented tags, then :func: tdfs4ds.plotting.plot_historian_xyinside the window of the question, or the default one (tdfs4ds.PLOT_HISTORIAN_DEFAULT_DAYS, stated in the answer). - Per period, opt-in: the question names a table or view of PERIODS and asks for its items
("for the
of ", "for each - of
", "pour les de "), optionally with conditions ("where > 1000", "of type A or B", "where the exceeded 30 kW"). The roles of the dataset's columns (the item's key, the key columns that match the historian's id columns, the start and the end) are read from the column documentation and the column types, never from a column's name alone. Each item is read on its own key values between its own start and end. A period dataset is never used unless named. - of
- Which historian: several historians could serve and the question names none (or names a tag several of them hold): a numbered choice; one holder only: used, and said.
Anything unclear (several candidate columns, tags or tables, a unit that is not documented, no
link between the dataset and the historian, a tag not found, period mode or not) is answered with
a short explanation and numbered rephrased questions built from the real names found; a numbered
reply runs the chosen one (pending["choices"]). Nothing is run before that.
_VS_RE
module-attribute
¶
_VS_RE = re.compile("\\s+(?:versus|vs\\.?|against|as\\s+a\\s+function\\s+of|in\\s+function\\s+of|en\\s+fonction\\s+d[eu']\\s*|contre|par\\s+rapport\\s+[Ă a]|over(?!\\s+(?:time|the\\b|a\\b|an\\b|last\\b|past\\b|\\d|each\\b|every\\b|all\\b|several\\b)))\\s+", re.IGNORECASE)
_LEAD_RE
module-attribute
¶
_LEAD_RE = re.compile("^.*?\\b(?:plot|chart|draw|show|graph|scatter|trace[rz]?|dessine[rz]?|montre[rz]?|affiche[rz]?)\\b\\s*(?:(?:me|moi|a|an|the|le|la|les|un|une)\\s+)?(?:(?:scatter|graph|chart|plot|courbe|graphique|nuage)\\s+(?:of|de|du|des|d')\\s*)?", re.IGNORECASE)
_RHS_STOP_RE
module-attribute
¶
_RHS_STOP_RE = re.compile('\\s+(?:for|per|using|with|from|in|on|over|during|between|where|of\\s+the|over\\s+the|since|until|pour|par|avec|dans|depuis|sur|entre|o[uĂ¹]|pendant|du|de\\s+la|des)\\b|[,;?!]|\\.(?=\\s|$)|\\(', re.IGNORECASE)
_PERIOD_OF_RE
module-attribute
¶
_PERIOD_OF_RE = re.compile('\\b(?:for|per|over)\\s+(?:the\\s+|each\\s+|every\\s+|all\\s+(?:the\\s+)?)?([A-Za-zĂ€-Ă¿][\\wĂ€-Ă¿-]*)\\s+(?:of|in|from)\\s+(?:the\\s+)?(?:dataset\\s+|table\\s+|view\\s+)?([\\w$#\\".]+)|\\bpour\\s+(?:les\\s+|chaque\\s+|tou(?:s|tes)\\s+les\\s+)?([A-Za-zĂ€-Ă¿][\\wĂ€-Ă¿-]*)\\s+(?:de\\s+la\\s+|du\\s+|des\\s+|de\\s+|d\')(?:dataset\\s+|table\\s+|vue\\s+)?([\\w$#\\".]+)', re.IGNORECASE)
_CLOCK_RE
module-attribute
¶
_CLOCK_RE = re.compile('\\b(real\\s+time|clock\\s+time|actual\\s+time|wall[-\\s]clock|calendar\\s+time|temps\\s+r[ée]el|heure\\s+r[ée]elle|date\\s+r[ée]elle)\\b', re.IGNORECASE)
_COND_START_RE
module-attribute
¶
_COND_START_RE = re.compile('\\b(?:where|with|whose|having|which|that|o[uĂ¹]|avec|dont|ayant|qui)\\b', re.IGNORECASE)
_CATEGORY_RE
module-attribute
¶
_CATEGORY_RE = re.compile('\\b(?:of|de)\\s+(?:the\\s+)?(type|category|cat[ée]gorie|class|classe|grade|family|famille|kind|sorte|model|mod[eè]le|status|statut)\\s+([\\w.\\-/]+(?:\\s*(?:,|\\bor\\b|\\bou\\b)\\s*[\\w.\\-/]+)*)', re.IGNORECASE)
_BUCKET_RE
module-attribute
¶
_BUCKET_RE = re.compile('\\b(?:per|every|each|by|averaged\\s+(?:over|per)|par|chaque|toutes?\\s+les|moyenn[ée]e?s?\\s+(?:sur|par))\\s+(\\d+\\s*)?(seconds?|secs?|minutes?|mins?|hours?|heures?)\\b', re.IGNORECASE)
_OPS
module-attribute
¶
_OPS = [('>=', '>=|\\bat\\s+least\\b|\\bgreater\\s+than\\s+or\\s+equal\\s+to\\b|\\bau\\s+moins\\b|\\bsup[ée]rieure?s?\\s+ou\\s+[ée]gale?s?\\s+[à a]\\b'), ('<=', '<=|\\bat\\s+most\\b|\\bless\\s+than\\s+or\\s+equal\\s+to\\b|\\bau\\s+plus\\b|\\binf[ée]rieure?s?\\s+ou\\s+[ée]gale?s?\\s+[à a]\\b'), ('<>', "<>|!=|\\bnot\\s+equal\\s+to\\b|\\bdifferent\\s+from\\b|\\bdiff[ée]rente?s?\\s+de\\b|\\bis\\s+not\\b|\\bn'est\\s+pas\\b"), ('>', '>|\\b(?:greater|more|higher|larger|longer|bigger|later)\\s+than\\b|\\babove\\b|\\bover\\b|\\bafter\\b|\\bapr[eè]s\\b|\\bpost[ée]rieure?s?\\s+[à a]\\b|\\bexceed(?:s|ed|ing)?\\b|\\bsup[ée]rieure?s?\\s+[à a]\\b|\\bplus\\s+grande?s?\\s+que\\b|\\bplus\\s+de\\b|\\bau[-\\s]dessus\\s+de\\b|\\b(?:a\\s+)?d[ée]pass[ée]e?s?\\b|\\bd[ée]passant\\b|\\bd[ée]passe\\b'), ('<', '<|\\b(?:less|lower|smaller|shorter|fewer|earlier)\\s+than\\b|\\bbelow\\b|\\bunder\\b|\\bbefore\\b|\\bavant\\b|\\bant[ée]rieure?s?\\s+[à a]\\b|\\binf[ée]rieure?s?\\s+[à a]\\b|\\bplus\\s+petite?s?\\s+que\\b|\\bmoins\\s+de\\b|\\ben[-\\s]dessous\\s+de\\b'), ('=', '==|=|\\b(?:is\\s+)?equal\\s+to\\b|\\bequals\\b|\\b(?:est\\s+)?[ée]gale?s?\\s+[à a]\\b'), ('=', '\\bis\\b|\\bwas\\b|\\best\\b|\\bvaut\\b')]
_BETWEEN_RE
module-attribute
¶
_BETWEEN_RE = re.compile('^(?P<col>.+?)\\s+(?:is\\s+|est\\s+|was\\s+)?(?:between|entre)\\s+(?P<a>\\S+(?:\\s*[A-Za-zµ°%]+)?)\\s+(?:and|et)\\s+(?P<b>\\S+(?:\\s*[A-Za-zµ°%]+)?)$', re.IGNORECASE)
_AGG_WORDS
module-attribute
¶
_AGG_WORDS = [('AVG', '\\b(?:average|mean|moyenne?)\\b'), ('MAX', '\\b(?:max|maximum|peak|pic)\\b'), ('MIN', '\\b(?:min|minimum)\\b')]
_THROUGHOUT_RE
module-attribute
¶
_THROUGHOUT_RE = re.compile('\\b(?:stay(?:s|ed)?|remain(?:s|ed)?|kept|always|throughout|(?:est\\s+|sont\\s+)?rest[ée]e?s?|reste(?:nt)?|toujours)\\b', re.IGNORECASE)
_ART_RE
module-attribute
¶
_ART_RE = re.compile("^(?:the|its|their|a|an|le|la|les|l'|son|sa|ses|leur|leurs|un|une)\\s+", re.IGNORECASE)
_START_WORDS
module-attribute
¶
_START_WORDS = re.compile('\\b(start\\w*|begin\\w*|d[ée]but\\w*|commenc\\w*|opened|from|since|d[ée]marr\\w*)\\b', re.IGNORECASE)
_END_WORDS
module-attribute
¶
_END_WORDS = re.compile('\\b(end|ends|ended|ending|stop\\w*|finish\\w*|fin|termin\\w*|closed|until|jusqu\\w*|arr[eĂª]t\\w*)\\b', re.IGNORECASE)
_KEY_WORDS
module-attribute
¶
_KEY_WORDS = re.compile('\\b(id|ids|identifier|identifiant|key|cl[ée]|code|number|num[ée]ro|nr|no|name|nom)\\b', re.IGNORECASE)
_GENERIC
module-attribute
¶
_GENERIC = {'id', 'ids', 'identifier', 'identifiant', 'number', 'numero', 'numéro', 'nr', 'no', 'code', 'key', 'the', 'of', 'a', 'an', 'le', 'la', 'les', 'de', 'du', 'des', 'which', 'where', 'on', 'in', 'is', 'was', 'this', 'that', 'each', 'row', 'value', 'name', 'column', 'en', 'est', 'par', 'for', 'per', 'one', 'un', 'une', 'at', 'to', 'by', 'with', 'and', 'et', 'or', 'ou', 'time', 'date'}
_EACH_ITEM_RE
module-attribute
¶
_EACH_ITEM_RE = re.compile('\\b(?:for\\s+(?:each|every|all\\s+(?:the\\s+)?)|per|pour\\s+(?:chaque|tou(?:s|tes)\\s+les))\\s+([A-Za-zĂ€-Ă¿][\\w-]*)', re.IGNORECASE)
_ID_PHRASE_RE
module-attribute
¶
_ID_PHRASE_RE = re.compile("\\b(?:for|on|of|in|pour|sur|de|dans)\\s+(?:the\\s+|la\\s+|le\\s+|les\\s+|l')?([A-Za-zĂ€-Ă¿]+)\\s+(\\d+(?:\\s*(?:,|and|et)\\s*\\d+)*)\\b(?!\\s*(?:minutes?|hours?|days?|weeks?|months?|years?|heures?|jours?|semaines?|mois|ans?|kg|t|bar|°C|%)(?![\\w°]))", re.IGNORECASE)
_HOW_EN
module-attribute
¶
_HOW_EN = {'hint': 'as written in the question', 'name': 'by name', 'catalog': "the dataset's entity (catalog)", 'description': 'by its documentation'}
_HOW_FR
module-attribute
¶
_HOW_FR = {'hint': 'comme écrit dans la question', 'name': 'par le nom', 'catalog': "l'entité du dataset (catalogue)", 'description': 'par sa documentation'}
_layout
¶
parse_vs
¶
(y phrase, x phrase) of "plot Y vs X" / "trace Y en fonction de X", else None. Pure.
parse_bucket
¶
The time bucket an A-vs-B chart is asked for ("per minute", "every 30 seconds", "par heure"), as
"tdfs4ds.plotting.plot_historian_xy, else None (the automatic one). A fast cycle
averaged over the automatic bucket can hide the relation (seen live: a 30-minute ramp averaged per 5
minutes drew 6 clusters), so the bucket can be asked. Pure.
parse_period_request
¶
{"noun", "name", "end"}: "for the
singular
¶
The user's noun in the singular, for "each
parse_hints
¶
The roles a rephrased question states in brackets after the dataset: "(key RUN_ID, LINE_NO = LINE_ID, from T_START to T_END)" / "(clé ..., de T_START à T_END)". Pure.
parse_clause
¶
One condition: {"phrase", "op", "value", "unit", "agg"} (value a list for BETWEEN / IN),
else None. Pure.
parse_conditions
¶
The conditions of a question's tail: category phrases ("of type A or B", "de catĂ©gorie A ou B") and clauses after where / with / avec / oĂ¹, joined by and / et. Pure.
resolve_tag_phrase
¶
The tags a phrase means: the exact name (case-insensitive); else the tags all of whose words
are in the phrase (match_tags); else the tags holding every word of the phrase ("oven
temp" -> L1_Oven_Temp.PV). Several = ambiguous (the caller asks). Pure.
_holds
¶
{phrase: [tags of o]} for the phrases o's documented tags resolve.
historian_choice
¶
Which historian serves phrases: {"use": object, "tags": {phrase: [tags]}, "note"} or
{"ask": skill result} or {"none": True} when there is no historian.
_with_historian
¶
q naming the historian fq, inserted after what to draw and before the items, conditions and window ("... for each run of X where grade is premium" + "using H" used to end as the value "premium using H", seen live). Pure.
ask_historian
¶
The numbered choice of a historian: name, documented description, tags it holds.
reformulate
¶
A short explanation and numbered rephrased questions; a number runs that question.
resolve_roles
¶
resolve_roles(columns: dict, descriptions: dict, *, entity=(), hist_ids=(), hist_descriptions=None, noun: Optional[str] = None, hints: Optional[dict] = None)
(roles, problems): the dataset columns playing each role, from documentation and types.
roles = {"key", "start", "end", "id_map": {dataset column: historian id column}, "how": {...}};
how says how each role was found (hint = written in the question, name, catalog,
description; how["id"] per historian key). problems [{"role", "candidates", "text"}]
(empty when every role has exactly one column; id_missing when a historian key has no column
in the dataset: the join is not possible).
- start / end: date/time columns - a start/end pair by name, else the one documented as a start and the one documented as an end;
- every historian key (id column): the dataset column with the same name (case and
_ignored), else the one whose documentation shares the most meaning words with the historian column's name and documentation (one best only); - key of each item: the dataset entity (catalog) minus the keys, else the column whose name, then documentation, says it identifies an item. Pure.
resolve_column
¶
resolve_column(phrase: str, columns: dict, descriptions: dict, *, kinds=('number', 'time', 'text')) -> list
Dataset columns a condition's phrase means: the exact name, else the columns of the right type whose name or documentation holds every word of the phrase. Pure.
_period_question
¶
_tag_phrases
¶
Documented tags of o named in text (exact names, then match_tags).
handle
¶
The historian requests of the module docstring, else None (the PLOT skill goes on).
Returns a skill result (plot_needs_detail), or {"result", "understood", "window"} for
:func:tdfs4ds.agent.plot_skill._finish, or {"hit", "note"}: the historian to draw the
usual way (one holder of the tags named).
_name_historian_in_choices
¶
Every rephrased question offered names the historian it was built for, so choosing it never asks "which historian?" again (seen live: a confirmation "1" re-opened the historian choice, a loop).
_without_conditions
¶
question without its conditions (the clause after where / with / that following the period dataset, or after the first "where" when no dataset is named) and without its category phrases. Pure.
_documented_period_tables
¶
The names among period_names whose column documentation describes a start and an end (a table of periods), so a suggestion never points at a feature dataset with no period (seen live). Pure.
_plain_conditions
¶
A plain chart (no table of periods) with a "where" condition: a condition applies to rows of a table of periods, so it is never applied to a time window nor dropped in silence (seen live: "heater power for line 3 over the last 2 days where the oven temperature is above 200" drew the oven temperature too and ignored the condition). The chart without it and the per-period form are offered.
_per_items_without_dataset
¶
"for each run where grade is premium plot the pressure": items of a table of periods asked for, but no table named. Answered with the tables whose name or documentation names the item (rephrased questions naming each), never by drawing the plain historian (seen live: the condition and the items were silently dropped). None when the question does not ask for items, or names an id of the historian ("for each line").
_close_tags
¶
No tag has all its words in the question, but some share one ("plot the temperature" ->
OVEN_TEMP.PV of two historians): numbered rephrased questions, one per (historian, tag), so a
number runs one (seen live: "I could not tell what to plot", then "2" drew nothing). None when no
tag shares a word.
_ask_tag
¶
Period or A-vs-B mode with no tag named (seen live: an empty chart request was sent, "Plot over time"): the documented tags, as rephrased questions.
_conditions_tail
¶
The conditions of q as written (" where weight > 900 kg"), to keep them in a rephrased question.
id_filters
¶
[(historian id column, [values], span)] for "on line 2", "for lines 1 and 3", "pour la ligne 2":
the word names an id column (by its name or its documentation), the numbers are its values. Pure.
_window_in_conditions
¶
The conditions of a per-period question hold something read as a window. Pure.
_window_outside_conditions
¶
The time window of a per-period question, read OUTSIDE its conditions: "where weight between 700
and 1000 kg" or "where PRODUCTION_DAY is between
_alternatives
¶
Up to n complete tag tuples from per-phrase candidates (a None takes the documented tags).
_ask_mode
¶
A tag and a dataset named, but no "for each
understanding
¶
understanding(fr: bool, *, historian, tags, xy, dataset=None, noun=None, roles=None, ds_conds=(), tag_conds=(), window_text=None, n_periods=None, n_left=0, clock=False) -> list
What the agent understood, as bullets written by code (EN / FR). Pure.
_hinted
¶
The roles, every one written out in the rephrased question (it then runs as given).
_period_alternatives
¶
_period_alternatives(fr, tags, xy, noun, dsq, roles, problems, ds_conds, tag_conds, columns) -> list
Up to three rephrased questions: each ambiguous role / condition filled with one candidate.