Jelajahi Sumber

add template example and doc for systemdate neuron

nico 8 tahun lalu
induk
melakukan
acdf0233d4

+ 116 - 0
neurons/systemdate/README.md

@@ -0,0 +1,116 @@
+# Systemdate
+
+## Synopsis
+
+Give the current time from the system where Kalliope is installed. Return a dict of parameters that can be used in a template.
+
+## Options
+
+| parameter     | required | default | choices     | comment                                                               |
+|---------------|-----------|---------|-------------|-----------------------------------------------------------------------|
+| say_template  | no        |         |             | Say template used to make Kalliope speak out loud returned parameters |
+| file_template | no        |         |             | Like a say_template but from a file for complex usage                 |
+| cache         | no        | FALSE   | True, False | Should be set to False as audio output will changes at every minute   |
+
+
+## Return Values
+
+| name      | description                                       | type   | sample |
+|-----------|---------------------------------------------------|--------|--------|
+| hours     | Hour (24-hour clock) as a decimal number [00,23]. | string | 22     |
+| minutes   | Minute as a decimal number [00,59].               | string | 54     |
+| weekday   | Weekday as a decimal number [0(Sunday),6].        | string | 4      |
+| month     | Month as a decimal number [01,12].                | string | 4      |
+| day_month | Day of the month as a decimal number [01,31].     | string | 12     |
+| year      | Year with century as a decimal number             | string | 2016   |
+
+
+## Synapses example
+
+Simple synapse that give the current time with only hours and minutes
+```
+ - name: "time"
+    neurons:
+      - systemdate:
+          say_template:
+            - "It' {{ hours }} hours and {{ minutes }} minutes"
+    signals:
+      - order: "what time is it"
+```
+
+Synapse that give complete date and time with a template file.
+```
+ - name: "time"
+    neurons:
+      - systemdate:
+          file_template: en_systemdate_template_example.j2            
+    signals:
+      - order: "what time is it"
+```
+
+
+## Templates example 
+
+This template will transcribe received numbers from the neuron into natural language
+```
+"It's {{ hours }} hours and {{ minutes }} minutes
+```
+
+This template, which it must be placed in a file_template, will give the complete date and time.
+```
+{% set day_of_week = {
+    "0": "sunday",
+    "1": "monday",
+    "2": "tuesday",
+    "3": "wednesday",
+    "4": "thursday",
+    "5": "friday",
+    "6": "saturday"
+    }[weekday] | default("")
+-%}
+
+{% set month_word = {"1": "january", "2": "february", "3": "march", "4": "april", "5": "may", "6": "june", "7": "july", "8": "august", "9": "september", "10": "october", "11": "november", "12": "december"}[month] | default("") -%}
+
+{% set day_month_formated = {
+    "1": "first",
+    "2": "second",
+    "3": "third",
+    "4": "fourth",
+    "5": "fifth",
+    "6": "sixth",
+    "7": "seventh",
+    "8": "eighth",
+    "9": "ninth",
+    "10": "tenth",
+    "11": "eleventh",
+    "12": "twelfth",
+    "13": "thirteenth",
+    "14": "fourteenth",
+    "15": "fifteenth",
+    "16": "sixteenth",
+    "17": "seventeenth",
+    "18": "eighteenth",
+    "19": "nineteenth",
+    "20": "twentieth",
+    "21": "twenty-first",
+    "22": "twenty-second",
+    "23": "twenty-third",
+    "24": "twenty-fourth",
+    "25": "twenty-fifth",
+    "26": "twenty-sixth",
+    "27": "twenty-seventh",
+    "28": "twenty-eighth",
+    "29": "twenty-ninth",
+    "30": "thirtieth",
+    "31": "thirty-first",
+
+}[day_month] | default("") -%}
+
+It' {{ hours }} hours and {{ minutes }} minutes.
+We are the {{ day_of_week }} {{ month_word }} the {{ day_month_formated }} {{ year }}
+```
+
+## Notes
+
+> **Note:** As the neuron is based on the local system date, this last must be well configured. A good practice is the installation and configuration of a NTP client
+ to synchronize the time on your Linux system with a centralized NTP server.

+ 1 - 0
neurons/systemdate/template/en_template1.j2

@@ -0,0 +1 @@
+It's {{ hours }} hours and {{ minutes }} minutes.

+ 12 - 0
neurons/systemdate/template/en_template2.j2

@@ -0,0 +1,12 @@
+{% set day_of_week = {"0": "sunday", "1": "monday", "2": "tuesday", "3": "wednesday", "4": "thursday", "5": "friday", "6": "saturday"}[weekday] | default("") -%}
+{% set month_word = {"1": "january", "2": "february", "3": "march", "4": "april", "5": "may", "6": "june", "7": "july", "8": "august", "9": "september", "10": "october", "11": "november", "12": "december"}[month] | default("") -%}
+
+{% set day_month_formated = {
+{
+"15": "fifteenth"
+}
+}
+[day_month] | default("") -%}
+
+It' {{ hours }} hours and {{ minutes }} minutes.
+We are the {{ day_of_week }} {{ month_word }} the {{ day_month_formated }} {{ year }}

+ 5 - 1
neurons/systemdate/template/fr_template2.j2

@@ -1 +1,5 @@
-{{ hours }} heures et {{ minutes }} minutes précisément
+{% set day_of_week = {"0": "dimanche", "1": "lundi", "2": "mardi", "3": "mercredi", "4": "jeudi", "5": "vendredi", "6": "samedi"}[weekday] | default("") -%}
+{% set month_word = {"1": "janvier", "2": "février", "3": "mars", "4": "avril", "5": "mai", "6": "juin", "7": "juillet", "8": "août", "9": "septembre", "10": "octobre", "11": "novembre", "12": "décembre"}[month] | default("") -%}
+
+Il est {{ hours }} heures et {{ minutes }} minutes.
+Nous sommes le {{ day_of_week }} {{ day_month }} {{ month_word }} {{ year }}

+ 50 - 0
templates/en_systemdate_template_example.j2

@@ -0,0 +1,50 @@
+{% set day_of_week = {
+    "0": "sunday",
+    "1": "monday",
+    "2": "tuesday",
+    "3": "wednesday",
+    "4": "thursday",
+    "5": "friday",
+    "6": "saturday"
+    }[weekday] | default("")
+-%}
+
+{% set month_word = {"1": "january", "2": "february", "3": "march", "4": "april", "5": "may", "6": "june", "7": "july", "8": "august", "9": "september", "10": "october", "11": "november", "12": "december"}[month] | default("") -%}
+
+{% set day_month_formated = {
+    "1": "first",
+    "2": "second",
+    "3": "third",
+    "4": "fourth",
+    "5": "fifth",
+    "6": "sixth",
+    "7": "seventh",
+    "8": "eighth",
+    "9": "ninth",
+    "10": "tenth",
+    "11": "eleventh",
+    "12": "twelfth",
+    "13": "thirteenth",
+    "14": "fourteenth",
+    "15": "fifteenth",
+    "16": "sixteenth",
+    "17": "seventeenth",
+    "18": "eighteenth",
+    "19": "nineteenth",
+    "20": "twentieth",
+    "21": "twenty-first",
+    "22": "twenty-second",
+    "23": "twenty-third",
+    "24": "twenty-fourth",
+    "25": "twenty-fifth",
+    "26": "twenty-sixth",
+    "27": "twenty-seventh",
+    "28": "twenty-eighth",
+    "29": "twenty-ninth",
+    "30": "thirtieth",
+    "31": "thirty-first",
+
+}[day_month] | default("") -%}
+
+It' {{ hours }} hours and {{ minutes }} minutes.
+We are the {{ day_of_week }} {{ month_word }} the {{ day_month_formated }} {{ year }}

+ 5 - 1
templates/fr_systemdate_template_example.j2

@@ -1 +1,5 @@
-ma montre indique {{ hours }} heures et {{ minutes }} minutes
+{% set day_of_week = {"0": "dimanche", "1": "lundi", "2": "mardi", "3": "mercredi", "4": "jeudi", "5": "vendredi", "6": "samedi"}[weekday] | default("") -%}
+{% set month_word = {"1": "janvier", "2": "février", "3": "mars", "4": "avril", "5": "mai", "6": "juin", "7": "juillet", "8": "août", "9": "septembre", "10": "octobre", "11": "novembre", "12": "décembre"}[month] | default("") -%}
+
+Il est {{ hours }} heures et {{ minutes }} minutes.
+Nous sommes le {{ day_of_week }} {{ day_month }} {{ month_word }} {{ year }}