|
cum jabbar posted:Replace that laptop with something permanently attached to the machine that runs a web server. CarForumPoster posted:Computer hardware is cheap compared to technician time so I’m assuming you’re putting a dedicated laptop on the hardware. No, there aren't dedicated laptops attached to each machine. Yes, it would be easy if that was the case - hence the question. To elaborate, these "machines" are really just things like scopes and VNAs. We have scripts for operating them in particular ways (along with collecting/recording data in certain ways). Our engineers have their own laptops and want to be able to use these tools freely.
|
# ? Jul 5, 2023 23:30 |
|
|
# ? May 14, 2024 12:00 |
|
Cyril Sneer posted:No, there aren't dedicated laptops attached to each machine. Yes, it would be easy if that was the case - hence the question. Could you draw a use diagram that has these components and some idea of what scripts are where? It sounds like the current state of affairs is this: And what you want is...??this?? IDGI, provide the specifics. What problem you tryin to solve, what does success look like?
|
# ? Jul 5, 2023 23:57 |
|
Cyril Sneer posted:Hey guys. To what extend can these various web frameworks be used to control local hardware? maybe I'm just a poorly-trained orangutan, and maybe I've spent a lot of time overcomplicating poo poo, but that sounds like writing software that you'd have to deploy in order to avoid having to deploy software. it sorta sounds like having to put the laptop in your hands is the main issue, is remote desktop not a thing that can happen? I have a bad case of infatuation with solving business process issues using software.
|
# ? Jul 6, 2023 00:07 |
|
This might be similar? Our board assembly house tests the hardware with some code we provide, and getting them updates has been a pain for multiple reasons, so I set up some stuff so they can pull the latest version of whatever they need from GitHub. The steps are install Git, run a. bat that sets up the username and password (a fine grained PAT with access just to that repo), and clones the repo with the tool they and other scripts they may need (eg to pull the latest repo). Should work well, but the meeting to get them running is tomorrow. If you definitely need a web based answer, I think the computer would need something special installed so the web app can interface with the serial or USB or w/e
|
# ? Jul 6, 2023 00:14 |
|
CarForumPoster posted:Could you draw a use diagram that has these components and some idea of what scripts are where? The top is what we currently have. I'd elaborate though and say the scripts are really apps, featuring GUIs, that allow the user to interact with the hardware in various pre-defined ways. The bottom is sort-of what I want (sorry, can't edit the diagram right now): instead of the functionality provided via the local Python app, its provided "in browser" via a web app. I know you can do remote users connecting to a remote server to control remote-connected hardware (think all those cam sites where users can go in and control the camera). I want a remote user connecting to a remove server to control locally-connected hardware. StumblyWumbly posted:
I think this is what it all hinges on. Seems like there's no way for a app-in-browser to interact with the hardware on which its running.
|
# ? Jul 6, 2023 01:17 |
|
The only way it could be provided “in browser” is if either the server had direct access to the device, or the user accessing the website was running a server the front end could communicate with (or the backend, if it could reach the laptop somehow). If you can’t have a server connected to the device at all times, you need a middle man. The laptop becomes that middleman. So you would still need to install XYZ to the laptop, for the website to even attempt this. And they would still have to be connected to the device directly.
|
# ? Jul 6, 2023 01:31 |
|
There is webUSB and webserial, but they are new, and not fully supported, and requires JavaScript drivers. You could also run a web server on the laptop, and send it requests that correspond to commands, but this takes a lot of setup, and is a terrible security practice.
|
# ? Jul 6, 2023 01:56 |
|
LightRailTycoon posted:There is webUSB and webserial, but they are new, and not fully supported, and requires JavaScript drivers. I had completely forgotten they added the USB bullshit. So that _is_ an option, assuming "connecting to the device" is not the main barrier here. But then yeah, its _very_ new and not all that well documented (or supported) yet I imagine.
|
# ? Jul 6, 2023 02:15 |
|
LightRailTycoon posted:There is webUSB and webserial, but they are new, and not fully supported, and requires JavaScript drivers. OooooOOh, this looks promising!
|
# ? Jul 6, 2023 02:29 |
|
Isn't the easier way to go about this to stand up a basic web server on whatever's connected to the hardware? From there you can do all sorts of possibly dangerous things, such as running scripts/etc and you control it over http via a web browser? It's a security nightmare, but if it's limited enough it's not exactly rocket surgery. Edit: honestly remote desktop seems to solve most of these problems now that I read over it. FISHMANPET posted:I think the problem you actually want to solve is a better way to deploy the instrument control software onto the users' devices, because it seems like the pain point you have is having to get hands on keyboard to set this stuff up. Engineering a web app using cutting edge java script is probably way more complicated and prone to failure than a better system for deploying the control software you have already. Yeah I think this is probably accurate; it does sound like they're overcomplicating the problem. Falcon2001 fucked around with this message at 04:41 on Jul 6, 2023 |
# ? Jul 6, 2023 04:14 |
|
I think the problem you actually want to solve is a better way to deploy the instrument control software onto the users' devices, because it seems like the pain point you have is having to get hands on keyboard to set this stuff up. Engineering a web app using cutting edge java script is probably way more complicated and prone to failure than a better system for deploying the control software you have already.
|
# ? Jul 6, 2023 04:26 |
|
Yeah having worked years ago in a schools IT department, and now as a python developer, my (still very rookie) first reaction was that this doesn't sound like something you'd do in python, it's a domain/deployment question. So something I'd have dealt with on the domain or device level rather than kludging together some weird ad hoc stuff that's just going to be a nightmare to develop, implement, and maintain But I am also very very tired so I don't know how much I actually understand the issue at hand
|
# ? Jul 6, 2023 10:35 |
|
My company sells sensors, and we have some open source Python libraries for configuring and interfacing with them, but we'd like to make some advanced wireless features that we can sell as subscription software, because that's how the world works now. It seems like the way to paywall a Python library for Windows would be to have a separate server running out of an install/EXE, which does the real work including handling the licensing and communicating with the device, and the Python library would just be an API interface with the local server. Qoitech (https://www.qoitech.com/) does this for automating an interface to their OTII power supplies, and it seems to work ok with some issues (RasPi support seems janky, folks keep forgetting to log out and lose their license, etc). The issue with just doing it all in Python, of course, is our secrets are completely exposed. Has anyone seen a better way to do this?
|
# ? Jul 7, 2023 14:05 |
|
So you're saying you want to charge a subscription for a local device talking to a local network service that costs your company nothing ongoing? If you're not incurring recurring costs but you want to charge them to your customers, that's bullshit. It's fine to charge a subscription for a cloud service, for technical support, for ongoing software updates, etc. Things that actually have ongoing costs because they involve resources you're paying for, which you can then easily control access to. Unless I'm reading you wrong what you want to do is not OK and should not be encouraged or assisted. Yes a bunch of lovely vendors already do it, but we don't need more of it in the world.
|
# ? Jul 7, 2023 15:46 |
|
StumblyWumbly posted:My company sells sensors, and we have some open source Python libraries for configuring and interfacing with them, but we'd like to make some advanced wireless features that we can sell as subscription software, because that's how the world works now. It seems like the way to paywall a Python library for Windows would be to have a separate server running out of an install/EXE, which does the real work including handling the licensing and communicating with the device, and the Python library would just be an API interface with the local server. Qoitech (https://www.qoitech.com/) does this for automating an interface to their OTII power supplies, and it seems to work ok with some issues (RasPi support seems janky, folks keep forgetting to log out and lose their license, etc). You said that the libraries are open source, so what secrets are you trying to protect? If you mean "secrets" as in authentication details then those shouldn't be in your codebase anyway.
|
# ? Jul 7, 2023 17:26 |
|
wolrah posted:So you're saying you want to charge a subscription for a local device talking to a local network service that costs your company nothing ongoing? There's a lot of details I'm not providing because this is just a noxious conversation to have. I hate capitalism too. QuarkJets posted:You said that the libraries are open source, so what secrets are you trying to protect? If you mean "secrets" as in authentication details then those shouldn't be in your codebase anyway.
|
# ? Jul 7, 2023 18:48 |
|
Yeah I think this is why a lot of companies used to distribute hardware fobs. I would look at it from a perspective of doing a cryptographic validation of some kind, but as others have mentioned, there's just going to be a risk that a determined customer rewrites the libraries to bypass those checks and uses their new 'hacked' versions instead.
|
# ? Jul 7, 2023 19:44 |
|
What is the threat model your trying to protect against? Unless you're going to jump in to a bunch of DRM stuff, editing a straightforward license check out of an executable isn't particularly hard. If you're selling widgets to businesses, your main defense is your license agreement and customers unwillingness to commit crimes (even if it's very unlikely they'll ever get caught), not technical difficulty I would guess that it's not business worthwhile for you to do anything more than some trivial check that may be straightforward to bypass, but makes it explicit that the customer removing the "has_valid_license()" call is being naughty.
|
# ? Jul 7, 2023 21:09 |
|
The main threat would be folks trying to access features on the device that they don't have a license for, so we can do the actual check on the device, which is very secure. I'm not super strong on cryptography, it feels like we might be doing enough out in the open that the customer can figure out our magic crypto numbers. We'll look into that, but I'm not super worried about it since our customers are mostly businesses.
|
# ? Jul 7, 2023 21:16 |
|
You'll probably need to provide a token signed with your own company's certificate. API users would provide this credential when making a request, then the device could use the certificate's public key to validate the signature. This keeps all actual secrets still inside the company. As a bonus, you could frame it as "enhanced security" since you now have an authentication system thay didn't exist before
|
# ? Jul 7, 2023 21:52 |
|
Imagine you're debugging and you come across this for the first time since you'd written it, and you're trying to remember what the thing you were tracking is doing at this point, at any given pointcode:
I'm keeping it because it amuses me
|
# ? Jul 8, 2023 05:42 |
|
Son of Thunderbeast posted:Imagine you're debugging and you come across this for the first time since you'd written it, and you're trying to remember what the thing you were tracking is doing at this point, at any given point quote:There are only two hard things in Computer Science: cache invalidation and naming things. Too loving true.
|
# ? Jul 8, 2023 06:55 |
|
I'm about to start working on a new project shortly and I'm trying to get my team into using Pytest instead of the built in UnitTest framework. I like it a lot more and it seems universally liked as well, but a lot of the folks I'm working with haven't done a lot of Python, so I'm trying to figure out good arguments for using it. Unfortunately I'm kind of struggling with coming up with good advantages; especially since we already use the pytest runner, which happily handles Unittest. Anyone have any good suggestions? FWIW: I'm in a position to definitely dictate what we'll be using for the test suite but I'd prefer to be like 'oh yeah we're using this new thing you haven't done before because XYZ' instead of just 'here it is, deal'
|
# ? Jul 8, 2023 09:44 |
|
Falcon2001 posted:I'm about to start working on a new project shortly and I'm trying to get my team into using Pytest instead of the built in UnitTest framework. I like it a lot more and it seems universally liked as well, but a lot of the folks I'm working with haven't done a lot of Python, so I'm trying to figure out good arguments for using it. Unfortunately I'm kind of struggling with coming up with good advantages; especially since we already use the pytest runner, which happily handles Unittest. Anyone have any good suggestions? As someone who has successfully convinced a team of developers to the wonders of pytest, I feel I can answer this question. The big thing about pytest for me is ergonomics. Both simply in terms of code simplicity - functions vs. subclasses, assert support without having to use assertEquals etc., but also the extremely powerful fixtures and parametrization support out of the box. The best argument I provided was simply refactoring part of our existing test suite to pytest, and showing how much simpler and more expressive the tests ended up being. I'm thinking a similar approach might work for you - show just a small example from on of our UnitTest test suites refactored to using pytest, and in my experience, developers will jump on things that make their lives easier, which pytest for sure does in my opinion. Then, you can simply say "let's use [new project] to learn pytest in-depth." That is probably how I'd go about it, anyway.
|
# ? Jul 8, 2023 12:35 |
Depending on the kind of code you need to test, parametrization might even be a non-negotiable feature. Like if you have a complex calculation method you want to test with 100 different sets of inputs. One test function with 100 clearly marked inputs is way better than 100 nearly identical and super redundant test functions.
|
|
# ? Jul 8, 2023 12:45 |
|
Data Graham posted:Depending on the kind of code you need to test, parametrization might even be a non-negotiable feature. Like if you have a complex calculation method you want to test with 100 different sets of inputs. One test function with 100 clearly marked inputs is way better than 100 nearly identical and super redundant test functions. Oh absolutely, and if you want to get fancy with it you can do absolutely amazing property-based testing things with Hypothesis.
|
# ? Jul 8, 2023 12:54 |
|
Here's a little list in no particular order, none of them having anything to do w/ the test runner: 1. The unittest lib is old and crusty (low hanging example: camel-case method names). Pytest is not crusty, and its interface is pythonic. Using pytest will guide your coworkers who are less familiar w/ Python toward better practices elsewhere in the code. 2. Strong support for testing without classes, fixtures eliminating the need for setup/teardown methods being the main thing here. (They are a little bit magical though, which is actually points against pytest from me). 3. The focus on using python-native assert, rather than a bunch of methods I'm constantly having to look up, is liberating. 4. Pytest provides some helpful stuff like the "pytest.raises" context manager that I reach for all the time. Unittest offers self.assertRaises for this, but I believe the pytest version has a wrapper which is easier to work with than the raw exception object that assertRaises gives you. You can make unittest work, there's nothing catastrophically wrong with it, but I've never been on a team who didn't see pytest as the obvious choice. It's just next to 0 lift for quite a bit of benefit, particularly if you're already using the runner. The March Hare fucked around with this message at 22:45 on Jul 8, 2023 |
# ? Jul 8, 2023 22:40 |
It's annoying that Django tests are built on unittest. I wonder if they're ever planning on moving away from that?
|
|
# ? Jul 8, 2023 22:49 |
|
Data Graham posted:It's annoying that Django tests are built on unittest. I wonder if they're ever planning on moving away from that? There’s a pytest Django module
|
# ? Jul 9, 2023 05:59 |
|
what's the easiest way to plot county-by-county geographic data in python these days along with some good data sources? like say I want to plot rainfall, or average seasonal temperatures, and mosquito density for a county-by-county map of the USA. counties colored by amount. googling this leads down many not entirely useful rabbit holes. are arcgis and geopandas the current hotness? does arcgis only interface with... arcgis, which I generally understand is a nonfree api?
|
# ? Jul 10, 2023 23:04 |
|
pmchem posted:what's the easiest way to plot county-by-county geographic data in python these days along with some good data sources? I haven’t looked in three years but back then county by county was a bitch. I think I ended up doing it by zip assigning certain zip codes to certain counties based on a spreadsheet I found of that. IIRC some zips spam multiple counties but it was good enough for the problem I had then.
|
# ? Jul 10, 2023 23:20 |
|
I like plotly. I usually do zip codes/census tracts but it would work for counties too. Just need the right shapefiles.
|
# ? Jul 10, 2023 23:57 |
|
pmchem posted:what's the easiest way to plot county-by-county geographic data in python these days along with some good data sources? I have used geopandas in the past and found it very powerful (for creating static maps, if you want interactive maps I don't know). County shapefiles can be found here at different resolutions: https://www.census.gov/geographies/mapping-files/time-series/geo/carto-boundary-file.html Perhaps some of the data you need can be found here: https://www.ncei.noaa.gov/access/monitoring/climate-at-a-glance/county/mapping Although they have the data plotted at the county level already, so perhaps you can just use those maps if they are plotting the data you want plotted (they allow you to export as a png)?
|
# ? Jul 11, 2023 13:49 |
|
Jose Cuervo posted:I have used geopandas in the past and found it very powerful (for creating static maps, if you want interactive maps I don't know). yeah, that second link basically contains the sort of plots I want to make! except I want to also plot other county-level data series of my own (hence plot it all on my own) and perform other local analysis.
|
# ? Jul 11, 2023 22:52 |
|
For these types of maps I really like Plotly choropleths. It mostly just works, and plotly gets you a bunch of nice quality of life features with being able to zoom and pan plots in a notebook instead of fiddling with the axes.
|
# ? Jul 14, 2023 16:33 |
|
I've inherited some code that is Django/Django Rest Framework, but thought this is more of a general Python question. I have a function that takes a DRF object (type Job) and needs to get dispatched to a JobRunner of the correct type. In the middle is a "figure out what kind of serialization" that has business logic. I don't love the design, but primarily want to make this if..elif..else pattern much easier. How should I think about making the below less tedious. Some kind of metaprogramming or Enum that defines the mapping in a straightforward way, then just looking at the dict/mapping? Here's an example of what's going on currently: Python code:
|
# ? Jul 15, 2023 20:00 |
|
Use a dict, with the job.search_type as the key, and the serializer as the value.
|
# ? Jul 15, 2023 20:22 |
|
Looks like maybe a nested dict to handle the second if/else block there but still, same concept.
|
# ? Jul 15, 2023 20:33 |
What I like to do in situations like this, if at all possible, is to make use of inheritance. The get_serializer_class method is meant to be overridden in a subclass of whatever your main view class is; so if your view class is MyJobViewClass, you would have subclasses called MySite1JobViewClass and MySite2JobViewClass and so on like:Python code:
That way you avoid having any kind of if-elif-elif-etc or switch-type structure which is really ugly to my eyes and hard to maintain. Django and DRF are meant to leverage subclassing a lot so that you can differentiate your routes at the class level and then subclass these helper methods like get_serializer_class in tiny little one-liners that are highly expressive and maintainable. It also means you can leverage mixins and base classes, which means your helper methods can call their superclass methods: Python code:
This may or may not be helpful (I see you're using job as your class variable instead of self so you may be doing something I'm not seeing as I'm shooting from the hip without proofreading, but this is the pattern I like to use if it seems to fit your use case. Data Graham fucked around with this message at 21:49 on Jul 15, 2023 |
|
# ? Jul 15, 2023 20:57 |
|
|
# ? May 14, 2024 12:00 |
|
I was going to recommend dictionary dispatch, like a few other posters already did. This is much cleaner and easier to read than using classes and inheritance in my opinion.
|
# ? Jul 15, 2023 21:09 |