How should I write this in simple coding? - data-analysis

I am a beginner at coding and I am creating a script that can ask the number of cleaning products being used. Then, using that number (x), to ask (x) many times, to input the name of the product.
Any clue where to start?
My code so far:
char numCommCleaningProducts;
System.out.println("How many commercial products are being used? ");
numCleaningProducts = scnr.next().charAt(0);

Related

Variable.get() from Optionmenu not returning what I need to query mySQL

forgive me for shoddy coding/description of the problem. I'm new to programming and this is my first question!
Anyways, I am building a simple inventory system with tkinter while using mySQL as a database. Currently, I am working on a feature that would allow a user to pick a department using an Optionmenu and then get all the items in that department. I have the items listed in one table and the departments listed in another with a FOREIGN KEY connecting the items table to the primary key (department_string) in the departments table.
My goal is to have mySQL deliver a list of departments and then to have the Optionmenu use that list for it's options. I then need to query the database with the department selected in the Optionmenu to find all the items in that department. My problem is that variable.get() from the Optionmenu returns parentheses and commas that is first received when I query the database the first time. This makes it so I cannot directly input the variable.get() into the string in the cursor. Here is the code:
department_cursor.execute("SELECT department_string FROM departments")
department_list = department_cursor.fetchall()
variable = StringVar(search_window)
variable.set(department_list[0])
user_entry = OptionMenu(search_window, variable, *department_list)
***
cursor_b.execute("SELECT item WHERE department_string = " + "'" + str(variable.get()) + "'")
I believe the problem is that variable.get() provides the special characters like the parentheses and comma that came from the original mySQL query. For example if the departments are HR, Warehouse, R&D then mySQL returns [('HR',), ('Warehouse',), ('R&D',)] this is then fed into the Option menu which then variable.get() spits out something like ('HR',), and so mySQL doesn't recognize this.
So far the only things I can think of is to use a for loop to delete all the special characters in what the Optionmenu returns or to hard code what the string for each department should be. Both seem suboptimal and although I'm pretty new to programming I think it's a little too much like rube goldberg machine.
Anyways, if you made it this far, thank you so much for reading this! Once again, I'm brand new to all of this so any help you can give me is greatly appreciated!
.get() is going to return whatever is in the optionmenu. If the values you put into the optionmenu have the undesirable characters, the value you get out will too.
The database call is going to return a list (rows) of lists (columns), and it doesn't look like you're taking that into account.

Is there a way to automatically create categories from a list of items?

I want to add some recipes to a part of my Mediawiki site and have each ingredient create a relevant category.
This is easy to do by hand, but subject to human error - each ingredient has to be entered twice.
for example
* [[category:apples]] apples
* [[category:bananas]] bananas
* [[category:cherries]] cherries
This works, but I feel there should be a way to automate it however I'm not really sure of what the best way forward would be. Is there already an extension to do this (I've searched on all the terms I can think of), should I be writing a script ? Is there some other method to solve this that I should be looking at ?
You could use a template, lets call it Template:Ingredient,
<includeonly>* [[Category:{{{1}}}]] {{{1}}}</includeonly>
Then call it in your page with:
{{Ingredient|apples}}
This will both display the ingredient name and add the page to the category.

How do I calculate the importance/weight of input based on users reputation?

I have a couple systems which contain a users' table along with some form of karma/weight/reputation. Sometimes it's the number of posts a user has made, sometimes it's the number of up/down votes a user has received across all their activity on the site.
USER {
id int
name string
karma int
}
How do I use these numbers to calculate that user's "weight" or "authority"? For example, the vote of one long-time member is often worth much more than 4 votes from brand new users.
I was thinking about adding up the total points/karma/reputation of all members and then trying to come up with a 1-100 scale.
SUM(user.points) / COUNT(user.*) = average user points
Then something like
CEIL(userA.points / average user points) = their weight on an issue
However, there also needs to be a curve on the points this way as I don't want someone with 5,000 posts/karma to out weigh 20 new users votes.
Mathematically, your best bet is to weight by the log of the percentile ranking of user in question. However, that is painful in SQL.
Simpler would be to cheat and assume the mean is the same as the median (a very bad assumption statistically, but much simpler programmatically):
SELECT 1 - log10(SELECT COUNT (*) FROM user
WHERE (SUM(user.points) / COUNT(user.*)) < user.points)
/ SELECT (COUNT (*) from user))
In this way, your top 10% of karma would have one and a half the impact of your average user, almost twice the impact of a noob.
Changing the log base would scale this, obviously, where natural log (log() in mysql) would give the upper 10% 3 times as much impact as a noob, and twice the impact as average. Log2() is even more extreme. (Note: subtraction is required because the log will be negative.)
If you want a more severe effect you might try squaring the log. (Note: squaring makes the log squared positive, so addition is appropriate here.)
If you want a hyperprecise rule, you can go into standard deviations, but the sql gets cumbersome and slow. It all depends on how far down the rabbit hole you want to go....
There are probably some resources that can provide you with parameters for this, but you should probably decide exactly what you want rather than using some predefined model. I suggest you define some rules for which sets of users should be equivalent or which should outweigh each other (e.g. 10 0 karma users = 1 5k karma user) (equivalence is much easier to work with), which will very quickly produce parameters for some chosen equation.
Using log (as already suggested), some (fractional) power (like square root) or even just linear can work.
I suggest something like newKarma = a.karma^b + c, and it shouldn't be to difficult to solve a, b and c. I suggest you pick b rather than trying to calculate it. Using new users (with karma = 0) should make this quite easy to solve. Guessing values to get close to what you want can be easier than determining them mathematically (since some rules together won't fit any simple equation).
Note that c above is an offset to karma, which will give many new users more total karma than high-karma users. You may also want to think about a.(karma + c)^b, or a.(karma + c)^b + d. Analysing the rules you defined should tell you which one to use.
UPDATE: Added alternatives for c
EDIT: You have some options for SQL. A temp table (with sums) might actually be the fastest. You can also just use a view. A join on the same table might also be possible, though I'm not sure. Using a view would look something like: (for some chosen a,b,c and d) (you may also want to add indices to the view)
Votes(issueID, userID) // table structure
User(userID, karma, ...) // table structure
CREATE VIEW Sums AS
SELECT issueID, SUM(1*POWER(karma + 2, 3) + 4) AS sumVal
FROM Votes JOIN User ON User.userID = Votes.userID
GROUP BY issueID
Query:
SELECT (1*POWER(karma + 2, 3) + 4)/sumVal AS influenceOnIssue
FROM Votes JOIN User ON User.userID = Votes.userID
JOIN Sums on Sums.issueID = Votes.issueID
WHERE Votes.userID = #UserID AND Votes.issueID = #IssueID
A simplification may be to have a computed column that = 1*POWER(karma + 2, 3) + 4
The faster option would be to calculate the derived karma on insert/update, either by having an additional column and using triggers or just calculating in before you call insert/update, and calling insert/update with the new value.

How to write a simple JQuery integer division function

My webpage displays realtime data that is updated every 10 seconds from our PI server(historian server). I was recently tasked to take two peices of data that are allready displayed on my page and divide them, displaying the new result on a graph. I have very little experience with AJAX/JQuery, so I was wondering if someone out there can lend me a hand?
Clarification:
Hypethetically-
Say I have "Number of Grades" and "Sum of Grades" displayed on my page as basic integers. They are updated every 10 seconds from the server. I want to take those two pieces of live data, divide them, and display the result (in this case it would be the overall average grade). So, my page will display Number of Grades, Sum of Grades, and Average Grade all updated in real time, every 10 seconds.
I am unclear as to whether JQuery can simply take those values off the server and perform division on them and return a value, or if other steps need to be taken to achieve this. I'm completely shooting in the dark here so sorry in advance for any vagueness or lack of required information.Thank you. Some example code is given below:
<span class = 'PIdata' data-tag = 'NumOfGrades' data-on_pi_change = 'NumOfGradeChange'></span>
<span class = 'PIdata' data-tag = 'SumOfGrades' data-on_pi_change = 'SumOfGradeChange'></span>
I want to display a value that divides NumOfGrades by SumOfGrades.
var sumOfGrades = parseFloat($.('#SumOfGradesId').text());
var numberOfGrades = parseFloat($.('#NumberOfGradesId').text());
var result = fn(sumOfGrades , numberOfGrades);
$.('#AverageGradeId').text(result);
This will set the required value.
Simple Maths with jQuery - division
The above link seems to have the answer to your question! Basically just access numbers by their id you set, get the value, parse them into integers or floats, perform your calculation, then store the value into the spot you would like it to appear!

Ability to enter the same info into multiple PO lines

I am trying to discover if there is away to choose multiple Material#'s (or PO and PO Line#'s) in Access 2007/2010 so that if I want to enter the same info for all of them then I can just do it once rather than having to look up each individual Material# and enter the info multiple times.
We import Material#'s of our product and the PO#'s and the PO Line Item#'s from SAP into Access. My job is to look through each material# and see if the Buyer correctly benchmarked the price from the quote to verify we got the proper savings amount from our vendor. There are alot of times when a single PO will have up to 50 lines on it all for different material#'s but their specs and prices will all be the same. So rather than having to enter the same comment for 50 different material#'s, I am trying to find out if there is an easier way to choose the 50 material#'s and enter the comment once for all of them. Please let me know if there is a way as it would save me alot of time and my Purchase Analyst who helped build our Access data base doesn't think there is a way but I think there must be some way to do it, whether a Macro or something else they haven't thought of.
Thanks for any help you can provide!