How to Create a Job Calculator?

If it's just a tabular report,
then perhaps a monospaced display in window is enough ?

1 Like

I want to be able to modify the Rate column.

Pending more ambitious (HTML form) GUI, you could always have 11 KM variables holding rates,

local_PerfectMatchRate
local_ContextMatchRate
etc

and display / update them in a KM Prompt for User input action, before generating and displaying the report.

1 Like

Hey Hans,

For simplicity I'd probably either use BBEdit, Numbers, or Microsoft Excel. (Numbers, and BBEdit Lite are free.)

All are scriptable.

To do an editable Custom HTML Prompt with a table would be quite doable, but the learning curve is high.

-Chris

1 Like

I have created an HTML page with Seamonkey. I'm not sure if that is enough for a macro or that I should use something more complex (too complex for me at the time) with CSS:

example
(The values in the white table don't match those in analysis_new.xml in the ZIP.)

If the HTML page is enough for a macro, I'd be grateful if someone could show me how to link the words variable for the Perfect Matches (I can do the other ones myself).

Perfect Match Rate should be preset with 0,00 but also be an editable field. How to achieve that?

The names of the variables are as follows:

Perfect Matches: %JSONValue%local_analyse[1].attributes.words%
Context Matches: %JSONValue%local_analyse[2].attributes.words%
Repetitions: %JSONValue%local_analyse[6].attributes.words%
CrossFileReps: %JSONValue%local_analyse[5].attributes.words%
Locked: %JSONValue%local_analyse[4].attributes.words%
100%: %JSONValue%local_analyse[3].attributes.words%
95%-99%: %JSONValue%local_analyse[14].attributes.words%
85%-94%: %JSONValue%local_analyse[13].attributes.words%
75%-84%: %JSONValue%local_analyse[12].attributes.words%
50%-74%: %JSONValue%local_analyse[11].attributes.words%
New/AT: %JSONValue%local_analyse[8].attributes.words%
Total: %JSONValue%local_analyse[7].attributes.words%

Job Calculator - components.zip (6.0 KB)

1 Like

Let me first try to make my first HTML macro.

Have at it!

:sunglasses:

1 Like

New approach: I've taken the example macro from the wiki and adapted it to my needs.

Question: How can I get the variable %JSONValue%local_analyse[1].attributes.words% in cell B2?

JobCalculator.zip (20.8 KB)

The general approach, Hans, would be to have a JavaScript function that would be called when the value of any cell in the Rate column changes. The function would multiply the Words (probably delivered as an argument to the function) by the Rate and display that total in the Amount column.

Similarly any change in the Amount column would trigger another JavaScript function to display a new grand total.

These two functions would sit in the HTML header and be called by an onchange event within the HTML table's cells.

That's just a sketch. I'll see if I can put together a small demo of it tomorrow if it makes sense to you.

2 Likes

So here's Step 1 (everything but the JavaScript).

ss-599

I've rewritten your CSS and HTML, redesigning the form. Just a few point to note:

  • Everything is contained in one table (including the buttons)

  • Formatting is confined to the CSS for the most part

  • Colors revised to monochrome except the buttons which on hover indicate function

  • Text is aligned in the cells according to function

  • Cancel/Save buttons are ordered in the standard format

  • Added a Calculate button (perhaps temporarily for testing)

  • Just doing two rows for testing

  • Eliminated the jQuery and bootstrap imports (which were unused)

I've assumed (perhaps incorrectly) that you've already figured out how to get your Word counts from the XML into the form. So these are just static numbers.

I also note you use European decimal notation. I'm not, but I don't think it matters. You can try this form to see.

It's midday here and the middle of the night where you are, I suspect. I'll try to get the JavaScript cooking tonight.

Job Calculator.kmmacros (4.8 KB)

Keyboard Maestro Export

3 Likes

OK, here's a first pass. It shows how to set variables for word counts that will be used in the form. But it doesn't pull them from your XML.

ss-600

When you enter the last rate, the form automatically calculates all the totals in the gray cells. So no need for a Calculate button.

Pressing Return resets the form, which is probably a bad idea. You can set the behavior of the Escape and Return keys in KMInit.

function KMInit(){
	window.addEventListener("keydown",function(e){
		if (e.key == 'Enter') {
			e.preventDefault();
		}
	});
}

Job Calculator.kmmacros (5.9 KB)

Keyboard Maestro Export

2 Likes

Hello Mike, thank you for your big effort. Much appreciated! :pray:t2:

I've assumed (perhaps incorrectly) that you've already figured out how to get your Word counts from the XML into the form. So these are just static numbers.

Yes, @ComplexPoint has been very kind and helped me with that step.

I'll try to add rows for all word categories and put the JSON variables in them. Now that both the XML parsing and the HTML is controlled by JavaScript, this should be doable for me (at least, I'll try :slight_smile: ).

Your form has a Save button. I cannot see where the Grand Total is saved.

I inherited that from the HTML form in your download, Hans. I didn't know what you wanted it to do so I didn't take it any further.

You might want to save the HTML as a file that you can open in a browser or you might want to save particular information from it.

As it is now, on the named local variables are accessible by Keyboard Maestro outside the prompt. If you wanted to save totalAmt, for example, you would have to convert it to something that looks like pmWords. Keyboard Maestro can save localpmWords.

Here's a little fancier version that:

  • Formats numbers with separators and two decimals where appropriate
  • Does not run asynchronously (missed that setting before)
  • Disables the Return key
  • Autofocuses on right column fields
  • Displays the total Amount when you click the Save button

ss-602

Job Calculator.kmmacros (8.3 KB)

2 Likes

Thank you @mrpasini! What should I do with the Custom HTML Prompt.kmactions?

I'll try to put everything together this weekend and will post back here.

Oops, sorry, I keep doing that (exporting just the action I was last working on instead of selecting the entire macro for export). I've fixed the upload (8.3K now) to include the whole macro.

@mrpasini I have added variables for the rates, to preset them:

Could you please give me a hand to make the calculation correct again?

Another strange thing is that the cursor initially is placed in the 50% row, instead of the Perfect Matches row.

Thank you in advance!

version10.zip (161.5 KB)

Sure. I'll put something together based on your update a bit later today.

Meanwhile (for anyone following along), the cursor location is controlled by the word autofocus in the input tag. Just use one of those in the field you want to use first.

And tabindex=1 orders the field entry when you tab from one to the next. In my example prompt, it was used to go down the right column, assuming values in the left column were set by earlier code, as they were in the example. But still editable if required.

The totals in the last line are tallied with the += calculation. There's only one in my example prompt.

Sorry about the obscure variable names. I may revisit that later today.

Here's the v11 with a few substantial changes.

ss-604

It seems like you have values for all the fields from your XML data and some constant rates, so I've set the form to calculate totals when you display the form.

You can edit any of the fields to instantly update the Amount display but Totals will be blanked because it is no longer valid. To recalculate the totals, click the Update button. I didn't update automatically in case some fields are empty.

If that isn't the case, the easiest way to make the form automatically calculate the totals is to add the calculate() function to the getAmt() function in each Rate field. You can even add them to the Word field. Here's an example.

oninput="getAmt('fiftyWords','fiftyRate','fiftyTotal');calculate()"

Just depends on whether the fields might ever be blank. I've made minimal assumptions here (that Rate might be blank).

Minor changes:

  • Changed the tab widths to accommodate "Cross-fFile Repeitions" on one line

  • Wrote a function to return the Amount for any particular line so editing a line's Words or Rate will instantly show a correct Amount (and blank the grand totals until you click the Update button).

  • Only the Custom HTML Prompt was changed in this version (well, apart from the title)

Job Calculator v11.kmmacros (31 KB)

Keyboard Maestro Export

3 Likes

Thank you @mrpasini! This is very nice. I'll add two things to this macro:

  1. Get the analysis.xml from a translation package.
  2. Get the word rates from a tab-delimited text file.

Then I'll publish the macro in the Macro Library :).

2 Likes