Welcome! Log In Create A New Profile

Advanced

Unique Parts Count

Posted by reece.arnott 
Unique Parts Count
September 08, 2007 10:41PM
I've been thinking for a while now that it would be good to have a list of the number and quantity of unique parts needed for a variety of reasons. I was going to do a manual count and then I thought that it would probably be quite a simple query to add to the part lister.

Maybe add a button that says 'Generate Unique parts count report' or some such in the part list lookup. It would leverage off the queries its currently doing but be ordered by quantity.
(Zach, any comments about how hard this would be to do?)

It means we can see for the design of a repstrap what parts we need to put the most thought into when it comes to substituting in common parts for the RP parts the design calls for i.e. go for the ones that we need the most of first.

Also, in the short term we could use this to go from the top of the list down and see if we could eliminate the rare parts or substitute them for the more common ones.

In the slightly longer term we could use the list to go from the bottom up to look at the 'low hanging fruit' and see what would be the best things to design to be printed by the reprap itself.

It is possible that this may mean increased complexity of the design in the initial stages but I see it as a similar payoff to that of the way logic gates on computer circuits are produced.

You could have specialised gates going AND, OR, NOT, XOR etc. logic but the way it actually works is that there is only a single type of NAND gate required; the others can all be made from wiring a number of NAND gates together in a variety of ways. If you come up with a better/faster way of making a NAND gate, all logic circuits benefit.

In the more long term, once reprap takes off, we reach a certain point beyond which its not desirable to cut down the parts list any further but I don't think we're there yet and this would help us get to that point.

Its probably a bit late to be thinking of substituting parts for the current revisions to the circuit boards but it is something to keep in mind for the next set.

Thoughts?
Re: Unique Parts Count
September 10, 2007 06:13PM
hey reece,

this is exactly one of the applications i wrote that part lister for. what you're basically asking is for an output where the parts are listed by quantity, instead of name. it should be fairly easy to do something like that. its something i'll eventually get around to, but for now i'm focusing on 3 things: electronics, the mcwire machine, and darwin. once we get those things out the door, then i might revisit the part lister.

in the meantime, if you're really interested in working on this, the PHP code that the site runs on is in the repository (if you'd like to modify it), and the 2nd page is that unique parts list you're looking for, except only sorted by name, and broken down by type. you can definitely see what parts have the potential for elimination in that page.
Re: Unique Parts Count
September 10, 2007 09:19PM
Thanks, I'll look at it quickly when I get home tonight and maybe do something over the next couple of days.

Edited 1 time(s). Last edit at 09/13/2007 05:59AM by reece.arnott.
Re: Unique Parts Count
September 13, 2007 05:51AM
I can't figure out how to commit the files through Eclipse so here they are.

They are replacements for the controllers\main.php and views\main.statistics.php

The main.php file just has under the public function statistics() an array being set to the results from a query, specifically the query:

SELECT SUM(quantity) AS cnt, name, units
FROM raw_parts rp
INNER JOIN unique_parts up
ON up.id = rp.part_id
GROUP BY name
ORDER BY units, cnt DESC

And the main.statistics.php just displays this array in a table.

If I understand the structure of the database this should do what I'm wanting but I didn't know how to test this.

I assume thats what the bom-dev.rerap.org is for, but how to I upload the code changes to it?

Edited 1 time(s). Last edit at 09/13/2007 05:59AM by reece.arnott.
Attachments:
open | download - main.statistics.php (1.1 KB)
open | download - main.php (3.5 KB)
Re: Unique Parts Count
September 13, 2007 04:18PM
awesome!

thanks for those changes. its really exciting to get outside contributions. i added them to subversion, with a couple minor changes: i added the type column, as well as links to each type and each individual part.

one slight caveat: the way the system is setup right now, it holds multiple versions of each module, so just doing a select from raw_parts will get you a total overview of the whole system. a better way of doing it would to call the getUniquePartList() function on the Darwin v1.0 module, and then using that data to do the query to get the list info.

i'm working on getting the stuff transitioned over to a new server, and once i get that done, then i will be able to give you access to the server itself where you could try your changes out on the host. it also has svn access so you could commit your changes too. i'll let you know once that transition is finished (another week i think)
Re: Unique Parts Count
September 13, 2007 11:28PM
Thanks for putting that up.

It looks like my logic was a bit faulty as some of the figures are just plain weird. I think what it is that my query doesn't take into account what happens if the parent part is used more than once.

The pseudo-code for changing this is quite simple:

do
count=0
for each part
if parent != NULL do
quantity = quantity * parent.quantity
count=count+1
if parent.quantity=1 or 0 then parent=NULL
endif
endfor
while count > 0

Then use the sorting algorithm of your choice to sort by quantity.

I was hoping to use the SQL ORDER BY to not have to sort them myself and I was really hoping not to do much more than copy and paste as I don't know php at all!

For that sort of thing I'd need access to the bom-dev to play around as I'm sure to get it wrong a few times first. Oh, well. I guess I'll wait patiently till the new server comes up and try to read up a bit on php in the meantime.

I haven't got the scripts in front of me at the moment but is there anything like that already? That way I can do another quick copy, paste, change job.
Re: Unique Parts Count
September 14, 2007 09:25AM
your best bet is to take the output from UniquePart.getUniquePartList(), and apply your sorting to that. that way we're using the the same code/logic throughout the site to generate part lists.

the output is a UniquePartListClass. you can then just directly access the $uniques array in that... let me give you a little example. i may just end up putting this into the code.

//get the unique parts/quantities for darwin.
$part = UniquePart::byName("RepRap Darwin v1.0", 'module');
$list = $part->getUniquePartList(true);

//get an array of id => quantity, sorted by quantity.
$qty_lookup = array();
foreach ($list->uniques AS $unique)
$qty_lookup[$unique->id] = $list->getUniqueQuantity($unique->id);
arsort($qty_lookup);


okay, i actually just went ahead and did it. i've committed it and its now on the live site. i would love to get you access still though.
Re: Unique Parts Count
September 14, 2007 05:03PM
Thanks. I'd just got to the point of looking at getUniquePartList and figuring out that was doing exactly what I'd wanted. It would have taken a bit of research to find out about arsort though :-)

I'll probably still have a go at teaching myself php anyway and hopefully get up to speed relatively quickly.

Edited 1 time(s). Last edit at 09/14/2007 05:11PM by reece.arnott.
Re: Unique Parts Count
September 16, 2007 01:11PM
if you have any questions, just ask me. i've been doing PHP programming for about 6 years now, and its what i do as a full time job. =)
Sorry, only registered users may post in this forum.

Click here to login