Suggestions for coding a web-based engineering calculator - Page 1
Forum section: electronics / general

author: floobydust
author_rank: Super Contributor
timestamp: June 06, 2018, 06:45:22 pm
content: I use Excel for all my engineering calculations and it would be nice to just use a browser instead, and add a bit more depth instead of using zillions of tabs.On-line calculators I see using Javascript, but it seems primitive and you have to send out entire tables/database to the browser and are limited to simple calculations. Then your results are "0.00000132 uF" or "12512645.423 Hz"I tried Microsoft Visual Studio and it's a terrible cloud-based monster that took over my PC and demanded I always be signed in and send Microsoft user analytics.I can host php but not sure how to write code for the calculator underneath that. php seems to be the front-end but the back-end is where I get confused.I don't need a sql database for the part parameters, it's just math and a few arrays of data to work with. Reluctant to learn Python so any other programming language preferred.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 06, 2018, 08:26:46 pm
content: Do you have a typical example?JS is quite capable, but it's only a programming language. You have to add all the engineering features you want. There's lots of code out there for formatting SI units, for example, you just have to apply it. Or vector or matrix calculations, same idea. It's no MATLAB, it doesn't have all that stuff integrated.Example, my Coilcraft SPICE model converter is a few thousand lines (or, wait, was it less?) of neatly-formatted-and-commented JS. That includes a plotting feature, and basic output formatting.Regarding IO, you can't do that directly in the browser, for very good reasons...Instead, you have a few alternatives: copy and paste as text or encode (e.g., an image pastes as Base-64 encode); use a file-upload input button (pops open a dialog to select one file); set up drag-and-drop; or if you're working locally, put files in the same folder so they are accessible from the "server" as just another GET request. Likewise, saving can be done as creating a file download, or plain text in an object, or graphics on a canvas (can be copied to clipboard), or as POST data (only relevant with a server side application to receive it), but not as a direct file write or anything like that (again, for good reasons).You could always do spreadsheets on Google Docs, of course that's no better than Excel in the first place.Tim

author: floobydust
author_rank: Super Contributor
timestamp: June 06, 2018, 10:49:18 pm
content: A simple example is calculating resistors for a voltage divider.R1, R2, Vin, Vout ; given any three you can calculate the remaining quantity, but not in four different calculators please.If I leave a cell blank, then calculate that automatically oh lowly computer.My 32 year old Sharp calculator gives results in engineering units, calculate that automatically oh lowly computer.For product development I have to design from -40°C to +70°C under various regulatory standards.My spreadsheet gives me required resistor values rounded to EIA standard values, includes a power dissipation number and suitable resistor package, considers resistor voltage rating and pad-spacings, and calculates the window due to resistor tolerance and temperature. A real world voltage divider.I could spit out every EIA value, every resistor package, wattage, size, tempco in the JS code to the browser, but it's too much data and why not reside on the server, which could do iteration, store larger tables etc.When I get asked about the (real world voltage divider) running at 85°C ambient, reconsidering everything now adding temperature derating to the resistors, a server-side calculator can remember the old entered data and redo the calculation. Without having to type it all in again.I'm just trying to make something beyond a pocket calculator.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 06, 2018, 11:18:56 pm
content: Regarding persistence, you can do that on a single machine with local cookies. To share it by user login instead, requires server storage of course.There are a few online resistor calculators around, but I don't know of any quite that fully-functional. I'd be surprised if your pocket calculator has that built in, so you have to step through the calculation yourself, or program the computer how to do it, regardless. It's only a... lowly computer, as you say. It doesn't know what engineering units are until you tell it.I guess Google Docs really is the closest thing to what you're asking, but that has obvious problems:1. It's on someone else's server.2. Not everyone thinks about problems the same ways, or needs the same features. You could put your spreadsheets online, but would they be useful to anyone else?3. Not everyone writes spreadsheets the same way. Most are atrocious messes. If just anyone goes and puts up a spreadsheet, how many others will actually be able to use it -- or make heads or tails of what it's even doing?And then going up even further, it comes down to the good old: time - money - quality: pick two.I'd LOVE to write the engineering environment that you envision... but it's not going to be cheap or fast.Methinks you'll stick with grumbling while poking at your 32 year old Sharp calculator instead.So, that's why we are where we are today, right?Tim

author: rstofer
author_rank: Super Contributor
timestamp: June 07, 2018, 03:40:50 am
content: There are online calculators for various circuits all over the Internet. Find one you like and look at the HTML. I just looked at one and it looks like the actual calculation is done at the server but things like units are done in HTML with drop down boxes. It isn't what you want in the end but it is a place to start. Just open the page and right click to select 'View page source'. There are literally hundreds of these pages and you can pretty much just copy what has already been done plus some personal wrinkles.http://www.learningaboutelectronics.com/Articles/Low-pass-filter-calculator.phpAs you look through the page source, you will find some links to javascripts. You can click on the source to see the code. I didn't study it. It looks like a rather large library of functions.More useful might be the HP41CV calculator programhttps://www.microsoft.com/en-us/p/hp41cv/9wzdncrdmknr?activetab=pivot%3aoverviewtab

author: apis
author_rank: Super Contributor
timestamp: June 07, 2018, 10:51:46 am
content: You're sort of asking how to build a calculator (the old school ones) without any of that primitive analogue stuff and you don't wan't to spend the effort to learn digital stuff.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: June 07, 2018, 11:04:17 am
content: Quote from: floobydust on June 06, 2018, 06:45:22 pmIt is possible to build very complex systems in JavaScript. I seem to remember seeing a Commodore PET emulation once. The sky's the limit if you can commit to the learning curve.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 07, 2018, 07:18:33 pm
content: Scanlime is currently patching and porting an old PC game to asm.js. Take a look at past streams if you're so inclined:https://www.youtube.com/channel/UCaEgw3321ct_PE4PJvdhXEQThe program is loaded as an int_8 array and emulated from there. To fully emulate an 80s PC (including not just the CPU, but the quirky hardware too), requires '00s era CPUs, and to do it in JS on top of that (which is itself a virtual environment) probably requires '10s era CPUs. It's no small feat of virtualization, abstraction and -- compared to the original hardware -- bloat.On the upside, you can put your greedy emulator tendrils into every possible part of the program, hooking and extending functions, creating new input and output methods, extending sounds and graphics, etc.Indeed, actually, the overhead due to JS, today, is astonishingly small, for all the problems faced in compiling, and yes even profiling, live code. Typical figures are 30% overhead versus native. Hardly a few years difference in CPU requirements there.Tim

author: hendorog
author_rank: Super Contributor
timestamp: June 07, 2018, 07:26:50 pm
content: If you want to start with javascript and can program in other languages then I recommend trying this library:http://knockoutjs.com/It made my life a heck of a lot easier, and is much more approachable than the other options I tried.It provides an event driven - i.e. kind of a VB/Delphi like experience - which works very well.

author: Vtile
author_rank: Super Contributor
timestamp: June 07, 2018, 08:41:45 pm
content: Don't reinvent the wheel. Use some math engine ie. xcas/giachttps://www-fourier.ujf-grenoble.fr/~parisse/xcasen.htmlThe HP Prime -calculator is using that as CAS engine and Geogebra app is also build on top of it. The same author is behind (one of them) the CAS in HP48 family of older eng. calculators.

author: hendorog
author_rank: Super Contributor
timestamp: June 07, 2018, 08:51:15 pm
content: Quote from: Vtile on June 07, 2018, 08:41:45 pmThat is cool.But at the same time it is a great example of a website which needs a decent frontend web developer badly.

author: Vtile
author_rank: Super Contributor
timestamp: June 07, 2018, 08:57:14 pm
content: Well it is just a homepage of the authors "hobby project".

author: hendorog
author_rank: Super Contributor
timestamp: June 07, 2018, 09:03:27 pm
content: Quote from: Vtile on June 07, 2018, 08:57:14 pmYeah I know, and I don't want to knock it too much, but the constant dialog box popping up saying 'Computations would be faster in Firefox' fired me up

author: Vtile
author_rank: Super Contributor
timestamp: June 07, 2018, 09:29:11 pm
content: In my phone it reguges to work. Here is the sites roothttps://www-fourier.ujf-grenoble.fr/~parisse/

author: Howardlong
author_rank: Super Contributor
timestamp: June 07, 2018, 09:41:14 pm
content: Quote from: T3sl4co1l on June 07, 2018, 07:18:33 pmImteresting, I wrote a PC emulator back in 1997/98 when Windows CE was released so you could run DOS programs on the MIPS processors they used. I got as far as being able to run real mode Windows in CGA graphics. EGA and VGA are a lot harder to emulate as they’re not simple memory maps in many of the graphics modes.For this I had to emulate the CPU, graphics card, interrupt controller, BIOS etc etc. Much of the BIOS you could paravirtualise... but remember that 20 years ago, virtualisation wasn’t a thing outside of mainframes. I also discovered an undocumented 8086 processor feature was used in MS DOS, I can’t remember what that was, but it took a couple of weeks of very late nights tracing through MS DOS to find it.Sadly, although I had fully functioning code, another chap was coincidentally working on a very similar thing, which was eventually sold commercially called PocketDOS, and his implementation ran about twice as fast as mine. To this day, despite plenty of head scratching, I have no idea how he achieved that, I was already right down deep in assembly langauge hand optimising everything. It was an interesting piece of work though even though it came to nothing commercially.

author: ajb
author_rank: Super Contributor
timestamp: June 07, 2018, 09:44:45 pm
content: Quote from: floobydust on June 06, 2018, 10:49:18 pmCompared to a modern webpage full of images, complicated stylesheets, chunky scripts providing rich UX, and, of course, ads, I have a hard time imagining that your static assets for such a calculator are really all that heavy! By the time you account for the transaction overhead, sending problems to and retrieving solutions from the server will pretty soon eat up more bandwidth, and spreads the required transfer time out through the entire user session instead of just getting it all over with at the beginning. Plus if you do everything client side you can let browser caching help you out so the whole thing doesn't have to load every time.The only real benefit I can see to doing the calculations server side is if you want to hide some secret sauce from the user, or be able to save some sort of state to be accessible across different PCs/users.

author: hendorog
author_rank: Super Contributor
timestamp: June 07, 2018, 10:09:02 pm
content: Quote from: ajb on June 07, 2018, 09:44:45 pmMod this up !Recently I've been abusing javascript in the interests of getting stuff done quickly, and it is remarkable what you can get done with it. When pushing the limits I did notice that Firefox fell over in a big way, and Chrome kept on trucking. What I was doing was pretty crazy so I wouldn't blame Firefox.But massive cross browser performance differences is something to test for if you go silly client side with large data.

author: Deridex
author_rank: Regular Contributor
timestamp: June 08, 2018, 03:52:33 am
content: Quote from: floobydust on June 06, 2018, 06:45:22 pmI'm using it for coding smaller pieces of software. And i am not signed in , so no cloud, and as far i know, it only sends telemtry. I also tried QT-Creator which seems to take significant more discspace than Visualstudio. But alot people still seem to like it.About a calculator:Have you tried Microsoft Mathematics ? I think it's free since a few years and it's quite powerfull.

author: Vtile
author_rank: Super Contributor
timestamp: June 08, 2018, 03:24:24 pm
content: There is also FreePascal with Lazarus IDE/RAD which is mature (but somewhat in shadows) toolchain for Object Pascal. It compiles the basic code to all major OSes and do static (standalone) executables so no installation required for your creations and the dialect is Delphi and Turbo Pascal compatible. The Lazarus itself and FreePascal compiler are both written and compiled with FreePascal (&asm).Plus thing is that the code (mnemonics) is easier to read and maintain if you are not die hard bit tweaker than many C-family languages with eye test with case sensitivity etc.. Python is of course another route.None of these are in the browser obviously. Unless you use Smart Mobile Studio, which compiles Object Pascal directly to HTML5.