Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

porting to v2 #6

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open

porting to v2 #6

wants to merge 42 commits into from

Conversation

jasmine8988
Copy link
Contributor

@jasmine8988 jasmine8988 commented Apr 13, 2023

1.前置

  • 在FarmDashboard/da 新創一個py檔,命名為sa.py
  • 新增iottalk-py==2.3.1到FarmDashboard/requirement.txt,讓sa.py可以使用iottalk-py (v2)的套件
  • 加入from iottalkpy.dan import Client, DeviceFeature, NoData
  • 加入from iottalkpy.dai import DAI, module_to_sa

2.創建一個Class取名為SaClass,放入iottalkpy/dai所需之參數及function

  • dai/module_to_sa裡面放的參數類型要為attribute,因此須將dai裡Class DAI所需之參數(ex.api_url , device_name , device_addr...等)跟odf_function,包在Class裡並且實體化後,再帶進module_to_sa
  • 透過multi-processes執行module_to_sa(sa)

3.動態產生以當前odf為名的odf_function

  • 建立def run,這裡的run()跟FarmDashboard/DAI裡的_run()做的事一樣
  • 因為iottalkpy/dai/on_data是透過抓取跟df_name相符的function去做執行,利用setattr(),動態地在SaClass裡產生以當前odf為名且執行run()的odf_function

4.server.py裡的_start_da裡的from da.DAI import main as da,改成from da.sa import main as da

@jasmine8988 jasmine8988 requested a review from Ksoy April 13, 2023 09:25
@jasmine8988
Copy link
Contributor Author

jasmine8988 commented Apr 20, 2023

new: 讓使用者自定要使用V1版本還是V2版本

  • config.py新增常數IOTTALK_VERSION=1,並加上V1的CSM_HOST
  • sever.py的_start_da()改成
    def _start_da():
    if config.IOTTALK_VERSION == 1:
    from da.DAI import main as da
    elif config.IOTTALK_VERSION == 2:
    from da.app import main as da
    da()

@Ksoy
Copy link
Member

Ksoy commented Apr 21, 2023

幫我加一下 CHANGELOG.md ,記錄一下你這次更新加了什麼,之前沒記的就算了。
可以參考 https://keepachangelog.com/zh-TW/0.3.0/

@Ksoy
Copy link
Member

Ksoy commented May 3, 2023

要請你把前端的部份 (css, js, html) 另外開一個 branch哦,
一個 pr (branch) 只做一件事就好

@Ksoy
Copy link
Member

Ksoy commented May 3, 2023

要請你把前端的部份 (css, js, html) 另外開一個 branch哦, 一個 pr (branch) 只做一件事就好

可以先切回 master 開一個新的 branch 後,再用 cherry-pick 把要的前端 commit 撿過去就好
然後再把這個 branch 的前端 commit reset 或 revert 掉

@jasmine8988
Copy link
Contributor Author

OK 收到~我改一下


### Changed

- IoTtalk-v2可使用的dashboard(dynamic) (#a2fe8a6)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這句是什麼意思?CHANGELOG 裡儘量放明確一點的文字,最好是能一看就知道意思。

然後如果是過程中的變動,不是最後結果的就不用放了,
比如這句 dynamic 跟下面的 static,這是在做一樣的事,最後的結果是 dynamic 的話,那 static 就不需要放了。

CHANGELOG.md Outdated

### Changed

- rename `app0330.py` to `app.py` (#e145710)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHANGELOG 的對象是最後要使用系統的人,像這種開發訊息就不需要放在 CHANGELOG 了,
放在 commit log 中就可以

app/api.py Outdated Show resolved Hide resolved
app/templates/base/css.html Show resolved Hide resolved
config.py Outdated
@@ -18,7 +18,12 @@

# IoTtalk server's 'IP' or 'DomainName' only, without any protocol 'http://' or 'https://'.
# ex: '8.8.8.8' or 'google.com',
# if you want to use IoTtalk V1 :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CSM_HOST 的註解應該跟 IOTTALK_VERSION 分開,因為不管 v1還是 v2 都需要 CSM_HOST。

IOTTALK_VERSION 的說明,應該是指出使用者連接的 CSM 所使用的 IoTtalk version,然後說明接受的值為 1 或 2,default 為 1 這樣

da/sa.py Outdated
'dm_name': 'DataServer',
'odf_list': [],
'is_sim': False}
alert_range = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alert_range 的東西先拿掉好了,目前用不到

da/sa.py Outdated
session = db.get_session()

for field in (session.query(db.models.field).all()):
profile = {'d_name': field.name + '_DataServer',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不需要 profile了吧,這是 v1 的用法,應該可以直接建立各個變數塞進 SaClass 中

da/sa.py Outdated

for field in (session.query(db.models.field).all()):
profile = {'d_name': field.name + '_DataServer',
'dm_name': 'DataServer',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dm_named_name 你這樣指定一次,可是沒有用到,又在 SaClass 中指定一次,
統一在這邊指定塞進 SaClass 中吧

da/sa.py Outdated
profile = {'d_name': field.name + '_DataServer',
'dm_name': 'DataServer',
'odf_list': [],
'is_sim': False}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_sim 應該用不到?

da/sa.py Outdated
alert_range = {}
query_df = (session.query(db.models.field_sensor)
.select_from(db.models.field_sensor)
.join(db.models.sensor)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只取 field_sensor 的資料的話,有需要 join sensor 嗎?

jasmine8988 and others added 10 commits May 11, 2023 14:16
self.interval={}

Co-authored-by: Ksoy <[email protected]>
modify da.app to da.sa
add idf_list in SaClass,rename d_name to device_name,rename dm_name to device_model
在最後一行新增了Dashboard V2版的使用方法,說明如何使用能連接IoTtalk v2的Dashboard。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants