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

237 update and refactor examples #278

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

Conversation

WaltherTrgovac
Copy link
Collaborator

@WaltherTrgovac WaltherTrgovac commented Apr 30, 2024

Closes #237.

Current state of examples\ngsiv2 that have been worked on:

  • Changes in every example:
    • Logger does not show the name of the module and class, but only class
    • Logger does not show milliseconds anymore and I changed the order of day, month, year. Not sure what is the best practise, this can be easily adjusted.
    • Adjusted every example to Python 3.9

Before:
Before

After:
after2

Examples:

  • e01_ngsi_v2_context_basics.py: working ✅ (last checked: 16.05.2024)
    • Changes: fixed logger output, entity ids changed to the standard ones
  • e02_ngsi_v2_context_relationships.py: working ✅ (last checked: 24.04.2024)
  • e03_ngsi_v2_context_subscriptions_http.py: working ✅ (last checked: 21.05.2024)
    • Changes: reformatted subscription comment
  • e04_ngsi_v2_context_subscriptions_mqtt.py: working ✅ (last checked: 21.05.2024)
    • Changes: fixed deprecated methods, reformatted mqtt notifications, removed unused imports
  • e05_ngsi_v2_context_registrations.py: not completely working ⚠️ (last checked: 29.05.2024)
    • Changes: fixed deprecated methods, PEP-8 errors, and reformatted comments.
    • Notes: It seems as if the context provider weather station is not providing any data to the building that is supposed to be provided from the weather station when we query the building at the end of the example
  • e06_ngsi_v2_autogenerate_context_data_models.py: not working ❌ (last checked: 30.04.2024)
    • Notes: A very short example, but half of the code is deprecated, maybe it should be completely remade?
  • e07_ngsi_v2_iota_basics.py: not completely working ⚠️ (last checked: 29.05.2024)
    • Changes: fixed deprecated methods, typos, and pep-8 errors. Changed entity ids to the standard ones.
    • Notes: The code gets executed, but with one small error from logger: 2024-04-30 17:03:55,412 filip.clients.ngsi_v2.cb.ContextBrokerClient ERROR: Could not delete attribute 'on' of entity'sensor2' Reason: {"error":"NotFound","description":"The requested entity has not been found. Check type and id"}
  • e08_ngsi_v2_iota_paho_mqtt.py: working ✅ (last checked: 11.06.2024)
    • Changes: fixed deprecated methods, pep 8 errors, typos. Also fixed the error with random attribute values being posted differently in comparison to the logger output. Fixed QoS message from mqtt client.
  • e09_ngsi_v2_iota_filip_mqtt.py: working: ✅ (last checked: 12.06.2024)
    • Changes: fixed deprecated methods, adjusted mqtt callback function logger statements, adjusted temperature value to be in 'normal' range.
    • Note 📓 : This example is showing more just the capabilities of the library, but not on the actual use case. Some methods are just listed in the example, so it is a bit messy and not completely clear what the example wants to show. This example can be maybe structured better?
  • e10_ngsi_vs_quantumleap.py: working ✅ (last checked: 07.05.2024)
    • Changes: fixed PEP-8 errors, typos. Removed milliseconds from logger for better readability. Changed print statements for better readability.
    • Notes: clear_all() method at the start is causing this message from the logger: filip.clients.ngsi_v2.quantumleap.QuantumLeapClient ERROR: Could not load entity data
      Reason: { "description": "No records were found for such query.", "error": "Not Found" } This does not cause any negative impacts further in the code, but the output is not very clean.
  • e11_ngsi_v2_context_specific_models.py: working ✅ (last checked: 08.05.2024)
    • Changes: None
  • e12_ngsi_v2_use_case_models.py: working ✅ (last checked: 18.06.2024)
    • Changes: clear_context_broker() method was missing parameters, now they have been added.

TODO: The directories of the examples and the numeration of the examples has to be adjusted. For example, we have two examples with the number 11 in the ngsiv2 directory, and the examples in the basics directory also need adjustment. README.md then also needs to be adjusted accordingly.

@WaltherTrgovac WaltherTrgovac linked an issue Apr 30, 2024 that may be closed by this pull request
8 tasks
@Maghnie
Copy link
Contributor

Maghnie commented Jun 12, 2024

@WaltherTrgovac could you please update the examples readme file? Specifically:

  • 1. Fix the link of the settings-management example, which currently leads to the loggings example
  • 2. Let's use relative links instead of absolute ones, to always refer to the "current" branch
  • 3. Mention that the examples require a running FIWARE instance (should be obvious, but still) and link back to the relevant section with installation instructions in the main filip readme.

Copy link
Contributor

@Maghnie Maghnie left a comment

Choose a reason for hiding this comment

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

Thanks for the extensive initial updates!

@@ -43,8 +43,8 @@
fiware_header=fiware_header)
# View version
for key, value in cb_client.get_version().items():
logger.info("Context broker version" + value["version"] + " at url " +
cb_client.base_url)
logger.info(f"Context broker version: {value["version"]} at url: "
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger.info(f"Context broker version: {value["version"]} at url: "
logger.info(f"Context broker version: {value['version']} at url: "

Does this line run through in PyCharm? My IDE (VS Code) exited with a SyntaxError here because it couldn't handle nested quotation marks of the same type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. Python version 3.9 does not allow nested quotation marks of the same type. Now every example can also be executed in Python 3.9.

Copy link
Contributor

Choose a reason for hiding this comment

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

Line 17 states that this example uses the env file, but it doesn't look like it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it does actually read it, because if you try to change something in the env file, you will get errors in the example.

examples/ngsi_v2/e08_ngsi_v2_iota_paho_mqtt.py Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

This example still produces warnings. Can they be avoided?

Copy link
Collaborator Author

@WaltherTrgovac WaltherTrgovac Jun 18, 2024

Choose a reason for hiding this comment

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

This is happening due to the nature of the example. We could just comment out the part that is producing the warning. This is the part 3.2 in this case, but I think the point of the example is to show the methods and not an actual real case usage, but I am not sure.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are many nested quotation marks of the same type here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

@djs0109 djs0109 left a comment

Choose a reason for hiding this comment

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

Now there is some problem with the reading of .env.filip . It seems like the variables will only be correctly loaded when the .env.filip is put under the path of the examples, i.e. examples/ngsi_v2/ or examples/basics/ @WaltherTrgovac could you have a look on that? If necessary you can modify the filip/config.py, where the variables are loaded

@Maghnie
Copy link
Contributor

Maghnie commented Jul 2, 2024

Now there is some problem with the reading of .env.filip . It seems like the variables will only be correctly loaded when the .env.filip is put under the path of the examples, i.e. examples/ngsi_v2/ or examples/basics/ @WaltherTrgovac could you have a look on that? If necessary you can modify the filip/config.py, where the variables are loaded

Wasn't it always like that? I think in the config of filip it says that the env file should be in the working directory, so it's up to the user to take care of that.

@WaltherTrgovac
Copy link
Collaborator Author

Now there is some problem with the reading of .env.filip . It seems like the variables will only be correctly loaded when the .env.filip is put under the path of the examples, i.e. examples/ngsi_v2/ or examples/basics/ @WaltherTrgovac could you have a look on that? If necessary you can modify the filip/config.py, where the variables are loaded

If I am understanding this correctly, the method SettingsConfigDict in the class Settings is taking the path of the .env.filip file. It was set so that it is found only when the files to execute are in the same directory as the .env.filip.
I have now adjusted that path so that the file can be located anywhere in the repository. I use the glob python package for that. First I locate the path of the repository with GitPython package and use that as the root directory. Then I look through the whole repository for the .env.filip file. The problem is that the .env.filip is a hidden file and glob package supports searching for hidden files only from the Python version 3.11... 😞. If somebody knows a solution for the earlier versions of Python that would be great.
And another thing, I have no idea how to test this implementation, I have just tested it manually...

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.

Update and refactor examples
3 participants