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

Update channel setting #7

Closed
BECATRUE opened this issue Nov 8, 2024 · 0 comments · Fixed by #31
Closed

Update channel setting #7

BECATRUE opened this issue Nov 8, 2024 · 0 comments · Fixed by #31
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@BECATRUE
Copy link
Member

BECATRUE commented Nov 8, 2024

Feature you want to implement

A client should be able to update each channel setting, which is managed by the task handler implemented by #6.

There will be two APIs for update on/off, exposure time, and measurement period of a channel.

  • /operation/:channel/ (POST)
  • /setting/:channel/ (POST)

How the feature is implemented

What I will implement is as below.

Request to close WLM connection.

  • This should not be offered in request handler.

Request to start measurement of a certain channel

  • Check if WLM connection is running. If not, open connection.
  • Check if measurement of the channel is running. If not, start measurement.

Request to stop measurement of a certain channel

  • Check if there is no user who wants to measure the channel. If so, stop measurement.
  • Check if there is no user measuring any channel. If so, close WLM connection.

Request to set exposure time / measurement period

The corresponding DBs will be updated properly.

@BECATRUE BECATRUE added the enhancement New feature or request label Nov 8, 2024
@BECATRUE BECATRUE added this to the v1.0.0 (Tentative title) milestone Nov 12, 2024
@BECATRUE BECATRUE self-assigned this Nov 18, 2024
BECATRUE added a commit that referenced this issue Nov 21, 2024
BECATRUE added a commit that referenced this issue Nov 21, 2024
BECATRUE added a commit that referenced this issue Nov 21, 2024
BECATRUE added a commit that referenced this issue Nov 21, 2024
BECATRUE added a commit that referenced this issue Nov 21, 2024
BECATRUE added a commit that referenced this issue Nov 21, 2024
BECATRUE added a commit that referenced this issue Nov 21, 2024
BECATRUE added a commit that referenced this issue Nov 21, 2024
BECATRUE added a commit that referenced this issue Nov 21, 2024
BECATRUE added a commit that referenced this issue Nov 21, 2024
It was incorrectly set to `name`.

See also: #7
BECATRUE added a commit that referenced this issue Nov 21, 2024
BECATRUE added a commit that referenced this issue Nov 21, 2024
BECATRUE added a commit that referenced this issue Nov 21, 2024
BECATRUE added a commit that referenced this issue Nov 22, 2024
BECATRUE added a commit that referenced this issue Nov 22, 2024
BECATRUE added a commit that referenced this issue Nov 22, 2024
This resolves #7.

I implemented the features as below.
- Receive a request to start/stop measurement of a specific channel
through `operation/:channel/`.
- Receive a request to update exposure time or period of a specific
channel through `setting/:channel/`.

The detailed logic for WLM control can be found in #7.

To test these features, you can mock the `WLM` class. The following code
might be helpful.
```python
class WLM:
    def open(self):
        print('WLM is connected.')

    def close(self):
        print('WLM is disconnected.')

    def start_measurement(self):
        print('Measurement is stared.')

    def stop_measurement(self):
        print('Measurement is stopped')

    def set_exposure(self, exposure, channel):
        print(f'Exposure time of channel {channel} is set to {exposure}.')
```

And the example client code is as follows.
```python
import requests

BASE_URL = 'http://localhost:8000'

with requests.Session() as session:
    data = {'username': 'user1', 'password': 'OOOO'}
    response = session.post(BASE_URL + '/user/signin/', json=data)

    csrf_token = session.cookies.get('csrftoken')
    headers = {'X-CSRFToken': csrf_token}

    data = {'exposure': 1}
    response = session.post(BASE_URL + '/setting/1/', json=data, headers=headers)
    
    data = {'period': 1}
    response = session.post(BASE_URL + '/setting/1/', json=data, headers=headers)

    data = {'on': True}
    response = session.post(BASE_URL + '/operation/1/', json=data, headers=headers)
    # open WLM connection and start measurement of channel 1

    data = {'on': True}
    response = session.post(BASE_URL + '/operation/2/', json=data, headers=headers)
    # start measurement of channel 2

    data = {'on': False}
    response = session.post(BASE_URL + '/operation/1/', json=data, headers=headers)
    # stop measurement of channel 1

    data = {'on': False}
    response = session.post(BASE_URL + '/operation/2/', json=data, headers=headers)
    # stop measurement of channel 2 and close WLM connection

    response = session.post(BASE_URL + '/user/signout/', headers=headers)
    print(response.status_code)  # 200
```

P.S. I updated `.pylintrc` file to allow more similar codes like
`iquip`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant