here you go
(at this time I thought you mean article like an article in a newspaper)
you can
- hit r at first run. - test data gets made and saved
- use l - load - to load it
- Use s to save
then
- Use cursor left and right now.
- Use + to add article.
- Use Space Bar to start timer (referring to currently visible article) and e to end it.
Remark
to be honest, when you plan this for a real factory, this is not the way to go.
I mean there are databases like Microsoft Access for this purpose
also, when you have a factory with machines, you would to integrate the measuring with the machines there. Or with the humans.
Further questions after writing this sketch
You wrote:
Let me comment on this.
Let me understand the scenario first.
When the whole product is a Left Car Door
and every production event is one door that is finished.
So we measure the time each door needs and the average etc.
Is that scenario correct?
Detail Questions
You wrote you need the data for both, every production event AND for the whole product in total. I donāt think that is true. We have to distinguish beetween both. And save separately.
- Setup time: Makes sense only for production event imo.
- Total time: Makes sense for both.
- Cycle time:What is it, average for one door?
- Produced parts in total: makes sense only for the whole product imo.
- Parts destroyed by setup. makes sense only for the whole product imo.
- Faulty parts. makes sense only for the whole product imo.
- Parts produced and ok for next operation. makes sense only for the whole product imo.
- Dates and times. Makes sense for both.
- User IDās. Makes sense for both.
Am I correct in this?
Chrisir
// states
final int normal=0;
final int newArticleEnterName=1;
int state=normal;
// Main list of articles
JSONArray valuesArray1;
// for loading
boolean loaded=false;
int loadedIndex=0; // index referring to valuesArray1
// vars for making a new article (+)
String newArticleName="";
// vars for measuring Time (Space Bar and e)
boolean measuringTime=false;
int measuringTimeIndex=0;
String dateNew ="";
String timeNew ="";
String dateNew2 ="";
String timeNew2 ="";
void setup() {
size(1200, 600);
}
void draw() {
background(0);
switch(state) {
case normal:
text("r for test data (these are saved), s to save, l to load", 14, 14);
showLoadedScreen();
break;
case newArticleEnterName:
text("Enter new Name: "+newArticleName, 114, 114);
text("You can use Backspace. Submit with Enter.", 114, 214);
break;
}//switch
//
}
// -------------------------------------------------------------------------------------------
void showLoadedScreen() {
if (loaded) {
//
text("You loaded the file. Use cursor left and right now. "
+"Use + to add article. "
+"Use Space Bar to start timer and e to end it.",
214, 34);
if (measuringTime) {
text("measuring Time for \n"
+measuringTimeIndex, width-200, 200);
}
JSONObject currentArticle = valuesArray1.getJSONObject(loadedIndex);
int id = currentArticle.getInt("id");
String articleName = currentArticle.getString("article");
String number = currentArticle.getString("number");
JSONArray eventsArray=currentArticle.getJSONArray("events");
String eventsMessage="";
if (eventsArray==null) {
eventsMessage=" Empty ";
}
text(id +"\narticle name "+articleName +" ("+number+")\nEvents:"+eventsMessage,
33, 44);
int lineNumber=0;
if (eventsArray!=null) {
for (int i = 0; i < eventsArray.size(); i++) {
JSONObject event1 = eventsArray.getJSONObject(i);
int idEvent = event1.getInt("id");
String date = event1.getString("date");
String time = event1.getString("time");
String[] timeData = split (time, '-');
text(idEvent+". "+date+": time: "+timeData[0] + " to " +timeData[1],
55, 100+lineNumber*13);
lineNumber++;
}
}
}
}
// -------------------------------------------------------------------------------
void keyPressed() {
// depending on state
switch(state) {
case normal:
keyPressedNormal() ;
break;
case newArticleEnterName:
keyPressedNewArticleEnterName() ;
break;
}
}
//-----------------------
void keyPressedNewArticleEnterName() {
if (!loaded)
return;//leave
switch(key) {
case ENTER:
case RETURN:
// end of entering a new name
state=normal;
JSONObject article = new JSONObject();
article.setInt("id", valuesArray1.size());
article.setString("article", newArticleName);
article.setString("number", str(valuesArray1.size()));
JSONArray eventsArray=null;
article.setJSONArray("events", eventsArray);
valuesArray1.setJSONObject(valuesArray1.size(), article);
break;
case BACKSPACE:
if (newArticleName.length()<=0)return;
newArticleName=newArticleName.substring(0, newArticleName.length()-1);
break;
default:
if (key==CODED)
return; // leave
newArticleName+=key;
break;
}//switch
}//func
void keyPressedNormal() {
if (key!=CODED) {
switch(key) {
case 'r':
// make all pseudo articles from scratch and save them
String[] articleNames = { "Climate", "Work", "Music" };
String[] articleNumbers = { "0", "1", "2" };
valuesArray1 = new JSONArray();
for (int i = 0; i < articleNames.length; i++) {
JSONObject article = new JSONObject();
article.setInt("id", i);
article.setString("article", articleNames[i]);
article.setString("number", articleNumbers[i]);
JSONArray eventsArray=getEvents(i); // that's test data
article.setJSONArray("events", eventsArray);
valuesArray1.setJSONObject(i, article);
}
saveJSONArray(valuesArray1, "data/new.json");
println("saved");
break;
case 's':
//save
saveJSONArray(valuesArray1, "data/new.json");
println("saved");
break;
case 'l':
//load
valuesArray1 = loadJSONArray("new.json");
loaded=true;
loadedIndex=0;
println("loaded");
//
break;
case '+':
if (!loaded)
return;//leave
state=newArticleEnterName;
break;
case ' ':
// start
dateNew = day()+"/"+month()+"/"+year();
println(dateNew);
timeNew = hour() +":"+minute();
println(timeNew);
measuringTime=true;
measuringTimeIndex = loadedIndex;
break;
case 'e':
//stop
dateNew2 = day()+"/"+month()+"/"+year();
println(dateNew2);
timeNew2 = hour() +":"+minute();
println(timeNew2);
measuringTime=false;
JSONObject currentArticle = valuesArray1.getJSONObject(measuringTimeIndex);
JSONArray eventsArray=currentArticle.getJSONArray("events");
JSONObject event1 = new JSONObject();
int newID=0;
if (eventsArray!=null)
newID=eventsArray.size();
event1.setInt("id", newID);
event1.setString("date", dateNew);// assuming both dates dateNew and dateNew2 are the same!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
event1.setString("time", timeNew+"-"+timeNew2);
if (eventsArray==null) {
eventsArray = new JSONArray();
currentArticle.setJSONArray("events", eventsArray);
eventsArray.setJSONObject(newID, event1);
} else {
eventsArray.setJSONObject(newID, event1);
}
break;
}//switch
}//if
//----------------------------------------------
else {
if (!loaded)
return;//leave
switch(keyCode) {
case LEFT:
loadedIndex--;
if (loadedIndex<0)
loadedIndex=0;
break;
case RIGHT:
loadedIndex++;
if (loadedIndex>=valuesArray1.size()) {
loadedIndex=valuesArray1.size()-1;
println("Last");
}//inner if
break;
//
}//switch
}//else
}//func
JSONArray getEvents(int indexOfArticle) {
// test data
if (indexOfArticle==0) {
JSONArray eventsArray = new JSONArray();
String[] articleNames2 = { "11/09/2019", "13/09/2019", "17/09/2019" };
String[] articleNumbers2 = { "03:04-05:47", "13:19-18:44", "22:33-23:12" };
for (int i = 0; i < articleNames2.length; i++) {
JSONObject event1 = new JSONObject();
event1.setInt("id", i);
event1.setString("date", articleNames2[i]);
event1.setString("time", articleNumbers2[i]);
eventsArray.setJSONObject(i, event1);
}
return eventsArray;
} else if (indexOfArticle==1) {
JSONArray eventsArray = new JSONArray();
String[] articleNames2 = { "11/09/2014", "13/09/2015", "17/09/2016" };
String[] articleNumbers2 = { "03:04-05:47", "13:19-18:44", "12:33-13:12" };
for (int i = 0; i < articleNames2.length; i++) {
JSONObject event1 = new JSONObject();
event1.setInt("id", i);
event1.setString("date", articleNames2[i]);
event1.setString("time", articleNumbers2[i]);
eventsArray.setJSONObject(i, event1);
}
return eventsArray;
} else if (indexOfArticle==2) {
JSONArray eventsArray = new JSONArray();
String[] articleNames2 = { "11/09/2011", "13/09/2011", "17/09/2011" };
String[] articleNumbers2 = { "03:04-05:47", "13:19-18:44", "22:33-23:12" };
for (int i = 0; i < articleNames2.length; i++) {
JSONObject event1 = new JSONObject();
event1.setInt("id", i);
event1.setString("date", articleNames2[i]);
event1.setString("time", articleNumbers2[i]);
eventsArray.setJSONObject(i, event1);
}
return eventsArray;
} else {
JSONArray eventsArray = new JSONArray();
String[] articleNames2 = { "11/09/19", "13/09/19", "17/09/19" };
String[] articleNumbers2 = { "03:04-05:47", "13:19-18:44", "22:33-23:12" };
for (int i = 0; i < articleNames2.length; i++) {
JSONObject event1 = new JSONObject();
event1.setInt("id", i);
event1.setString("date", articleNames2[i]);
event1.setString("time", articleNumbers2[i]);
eventsArray.setJSONObject(i, event1);
}
return eventsArray;
}//else
}
//