Subject: DIAutomatic + APBark Tue Oct 15, 2019 6:00 pm
/* * this class enables time triggered actions. algorithmic logic examplified with * the bark action: the AGI will bark at some time, and continue doing so every * hour till the user replies with his signature catch frase. thus the AGI will * know the time to expect him home. next she will reply happily. the bark is * the alg while the happy reply is the alter alg. */
public class DIAutomatic extends DISkill { /* * this class enables time triggered actions. algorithmic logic examplified with * the bark action: the AGI will bark at some time, and continue doing so every * hour till the user replies with his signature catch frase. thus the AGI will * know the time to expect him home. next she will reply happily. the bark is * the alg while the happy reply is the alter alg. */ public Person master; int algMode[] = new int[1]; // mode of alg per algs: 0,1 alg,alter alg int algTime[] = new int[1]; // alg trigger time per alg(hence array). String algTosend = ""; private PlayGround playGround = new PlayGround();
public DIAutomatic(Kokoro kokoro, Person master) { super(kokoro); this.master = master; Arrays.fill(algMode, 0); algTime[0] = playGround.getHoursAsInt(); }
@Override public void input(String ear, String skin, String eye) { int hour = playGround.getHoursAsInt(); for (int i = 0; i < algMode.length; i++) { if (algMode[i] == 0) { if (algTime[i] == hour) { algTime[i] = playGround.getFutureHour(algTime[i], 1); algTosend = i + ""; specialAlgAction(i); return; } if (alterAlg(i, ear, skin, eye)) { algTime[i] = hour; algMode[i] = 1; break; } } else { if (algTime[i] != hour) { algMode[i] = 0; } } } if (!algTosend.isEmpty()) { this.setSentAlg(true); } }
@Override public void output(Neuron noiron) { switch (algTosend) { case "0": barkAlg(noiron); break; case "0mode2": masterGreetAlg(noiron); break; default: break; } algTosend = ""; }
private void barkAlg(Neuron noiron) { // example timed alg AbsAlgPart itte = new Chi(this.kokoro, this.getClass().getSimpleName(), new APBark(3, master)); String representation = "bark"; ArrayList<AbsAlgPart> algParts1 = new ArrayList<>(); algParts1.add(itte); Algorithm algorithm = new Algorithm("bark", representation, algParts1); noiron.algParts.add(algorithm); }
private void masterGreetAlg(Neuron noiron) { // example alter alg, to fire when respective conditions were met and after a // timed alg was fired. AbsAlgPart itte = new Chi(this.kokoro, this.getClass().getSimpleName(), new APSay(1, "i missed you")); String representation = "welcome"; ArrayList<AbsAlgPart> algParts1 = new ArrayList<>(); algParts1.add(itte); Algorithm algorithm = new Algorithm("welcome", representation, algParts1); noiron.algParts.add(algorithm); } }
APBark
Code:
package chobit;
public class APBark extends AbsAlgPart { // bark x times // pause y times // cycle z times // or till user present private int pauseCounter; private int barkCounter; private int pauselim; private int barklim; private int stopCounter; private String bark;
// times and stuff public class PlayGround { // int foo = Integer.parseInt(myString); public String getCurrentTimeStamp() { // SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// // dd/MM/yyyy SimpleDateFormat sdfDate = new SimpleDateFormat("HH:mm");// dd/MM/yyyy Date now = new Date(); String strDate = sdfDate.format(now); return strDate; }
public String getMinutes() { // SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// // dd/MM/yyyy SimpleDateFormat sdfDate = new SimpleDateFormat("mm");// dd/MM/yyyy Date now = new Date(); String strDate = sdfDate.format(now); return strDate; }
public String getSeconds() { // SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// // dd/MM/yyyy SimpleDateFormat sdfDate = new SimpleDateFormat("ss");// dd/MM/yyyy Date now = new Date(); String strDate = sdfDate.format(now); return strDate; }
public String getDayOfDWeek() { Date now = new Date(); Calendar c = Calendar.getInstance(); c.setTime(now); int dayOfWeek = c.get(Calendar.DAY_OF_WEEK); return convertToDay(dayOfWeek); }
private String convertToDay(Integer d) { String result = ""; switch (d) { case 1: result = "sunday"; break; case 2: result = "monday"; break; case 3: result = "tuesday"; break; case 4: result = "wednesday"; break; case 5: result = "thursday"; break; case 6: result = "friday"; break; case 7: result = "saturday"; break; default: break; } return result; }
public String getSpecificTime(enumTimes timeType) { // SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// // dd/MM/yyyy SimpleDateFormat sdfDate; String format = ""; switch (timeType) { case DATE: Calendar cal = Calendar.getInstance(); int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH); int Month = cal.get(Calendar.MONTH); int year = cal.get(Calendar.YEAR); return translateMonthDay(dayOfMonth) + " " + translateMonth(Month + 1) + " " + year; case HOUR: format = "HH"; break; case SECONDS: format = "ss"; break; case MINUTES: format = "mm"; break; case YEAR: format = "yyyy"; break; default: break; } sdfDate = new SimpleDateFormat(format); Date now = new Date(); String strDate = sdfDate.format(now); return strDate; }
public int getSecondsAsInt() { // SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// // dd/MM/yyyy SimpleDateFormat sdfDate = new SimpleDateFormat("ss");// dd/MM/yyyy Date now = new Date(); String strDate = sdfDate.format(now); return Integer.parseInt(strDate); }
public int getMinutesAsInt() { // SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// // dd/MM/yyyy SimpleDateFormat sdfDate = new SimpleDateFormat("mm");// dd/MM/yyyy Date now = new Date(); String strDate = sdfDate.format(now); return Integer.parseInt(strDate); }
public int getHoursAsInt() { // SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// // dd/MM/yyyy SimpleDateFormat sdfDate = new SimpleDateFormat("HH");// dd/MM/yyyy Date now = new Date(); String strDate = sdfDate.format(now); return Integer.parseInt(strDate); }
public String getFutureInXMin(int x) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, x); SimpleDateFormat df = new SimpleDateFormat("HH:mm"); return df.format(cal.getTime()); }
public int getFutureHour(int startHour, int addedHours) { return (startHour + addedHours) % 25; } public String getFutureFromXInYMin(int x, String y) { Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); try { cal.setTime(sdf.parse(y)); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } // all done cal.add(Calendar.MINUTE, x); return sdf.format(cal.getTime()); }
public String translateMonth(int month1) { String dMonth = ""; switch (month1) { case 1: dMonth = "january"; break; case 2: dMonth = "February"; break; case 3: dMonth = "March"; break; case 4: dMonth = "April"; break; case 5: dMonth = "May"; break; case 6: dMonth = "June"; break; case 7: dMonth = "July"; break; case 8: dMonth = "August"; break; case 9: dMonth = "September"; break; case 10: dMonth = "October"; break; case 11: dMonth = "November"; break; case 12: dMonth = "December"; break; default: break; } return dMonth; }
public String translateMonthDay(int day1) { String dday = ""; switch (day1) { case 1: dday = "first_of"; break; case 2: dday = "second_of"; break; case 3: dday = "third_of"; break; case 4: dday = "fourth_of"; break; case 5: dday = "fifth_of"; break; case 6: dday = "sixth_of"; break; case 7: dday = "seventh_of"; break; case 8: dday = "eighth_of"; break; case 9: dday = "nineth_of"; break; case 10: dday = "tenth_of"; break; case 11: dday = "eleventh_of"; break; case 12: dday = "twelveth_of"; break; case 13: dday = "thirteenth_of"; break; case 14: dday = "fourteenth_of"; break; case 15: dday = "fifteenth_of"; break; case 16: dday = "sixteenth_of"; break; case 17: dday = "seventeenth_of"; break; case 18: dday = "eighteenth_of"; break; case 19: dday = "nineteenth_of"; break; case 20: dday = "twentyth_of"; break; case 21: dday = "twentyfirst_of"; break; case 22: dday = "twentysecond_of"; break; case 23: dday = "twentythird_of"; break; case 24: dday = "twentyfourth_of"; break; case 25: dday = "twentyfifth_of"; break; case 26: dday = "twentysixth_of"; break; case 27: dday = "twentyseventh_of"; break; case 28: dday = "twentyeighth_of"; break; case 29: dday = "twentynineth_of"; break; case 30: dday = "thirtyth_of"; break; case 31: dday = "thirtyfirst_of"; break; default: break; } return dday; } }