pvs=['PV-NUMBER','PV-ARRAY','PV-IMAGE']# Define the PV list
epics_dict={}
forpvinpvs:
epics_dict[pv]=epics.PV(pv,auto_monitor=True)
while(notself.stop_signal.isSet()):
json_dict={}
forpvinepics_dict:
json_dict[pv]={}
ifepics_dict[pv].connected:
# Example of Array
ifpv=='PV-ARRAY':# The arrays need a list made by pairs of X,Y
y_data=list(epics_dict[pv].value)
x_data=list(linspace(0,10,len(y_data)))# in this case the X axis will go from 0 to 10
json_dict[pv]['value']=list(zip(x_data,y_data))
continue
# Example of Image
ifpv=='PV-IMAGE':# We need to create the PNG
try:
imarray=epics_dict[PV-IMAGE].value.reshape(154,206)# From the array I reshape into the size of the image
except:
imarray=zeros((154,206))# If I don't get the correct data I do a blank image
plt.imsave('/var/www/data/tmp-my_image.png',imarray,cmap='jet')# Save as tmp
os.rename('/var/www/data/tmp-my_image.png','/var/www/data/my_image.png')# Swap the tmp image with the final one. This trick is used to avoid blinking image in the final page.
json_dict[pv]['units']=epics_dict[pv].units# I set the units for all the PVs
try:
json_dict[pv]['value']=round(epics_dict[pv].value,3)# Where possible I round the value to three decimal digits
except:
json_dict[pv]['value']=epics_dict[pv].value
else:
json_dict[pv]['units']='n.c.'# If the PV is disconnected I assign n.c. as unit an blank value
json_dict[pv]['value']=''
tmp_json=json.dumps(json_dict)# Create the JSON from dictionary
tmp_json=tmp_json.replace('NaN','0')# Replace the occurences of NaN with 0
tmp_json=tmp_json.replace('Infinity','0')# Replace the infinities with 0
withopen('/var/www/data/my_file.json','w')asdatafile:# Write the final file
datafile.write(tmp_json)
time.sleep(0.5)# Refresh every half a second
forpvinepics_dict:# When the stop signal is set, it cancels all the auto monitor and disconnects
@@ -5,32 +5,43 @@ This repository contains the structure to create the public opi screens running
## Development
You should use docker for development:
If you want to contribute to the screens the sequence is the following:
1. Clone the repository
- Install Docker on your computer and clone the git archive
- Build the docker images with
```
docker-compose build
```
- Verify that you can run the current version of the screen with
```
$ docker-compose up
```
- Open your browser and go to http://localhost:8000
If this works, you can create your own screen going to PythonServer/screens and adding a new python script that listen for the PVs and generate a json file plus the images file in case you want to display also images. You can use the example.py as template.
2. Build the docker images
Once your script seems ok, you can load it in the main program that is PythonServer/pos-python-server.py
On the top you have to load your new class adding from screen.yourcode import yourbeautifulScreen.
At the end of the script you have to add a new thread variable and create an instance of your class.
```
$ docker-compose build
```
For the Python side is all, now for the website.
3. Start the application
- In the Website copy the dev directory into a new directory with the name of your screen.
- In the main directory edit the default.conf file and add in the location your repository after pvs|interlocks|instruments|dev, this is needed for docker.
```
$ docker-compose up
```
You should be able now to run again your docker-compose up with your new website as localhost:8000/yoursite. First try to see if your json file is correctly generated by thepython script going to localhost:8000/data/yourfile.json. If this file is present it means that the python code didn't crash (It is already a good result!).
Then on the website you have the editor mode where you can create your interface graphycally. The way to do it is very easy, in the top right corner you add the JSON file as source with a refresh rate of 1 second. In each cell you can define the kind of widget that you want. You can even create additional one with some Javascript, but if unsure ask to me.
4. Open your browser and go to http://localhost:8000
Once you think that you have a good page try to resize your browser window to different sizes and rearrange the cells according to the order that you want to have on different screens (mobile, desktop, etc.).
Finally save the dashboard json file and replace the one that you have in the folder of your local server. Edit the dashboard file and change the allow_edit from true to false.
Finally, if you want to have the page into the main menu, you have to edit all the index.html files of all the screens and add your menu in the <ulid="menu"> section.
You only need to rebuild the docker images if changing the nginx configuration or python server requirements.
During development, the WebSites and PythonServer directories are mounted as volumes so you don't need to rebuild the images
when changing the code.
When these steps are complete run again the docker-compose up and verify that everything works according to what you expected. If you think that the
The docker images are automatically built by giltab-runners when pushing to GitLab.
You can now commit your project and push in a new branch, then make a pull request on the gitlab website. I will review the changes and add to the main repository.
To deploy to production, you should tag and push to GitLab:
To deploy to production (for Emanuele), you should tag and push to GitLab: