protected Schedule getEnhancementPolicySchedule(FeedingPolicy fp) { Vector sched_els = new Vector(0); String[] nsns = {FRESH_FRUITS, FRESH_VEGETABLES}; if (fp != null) { RangeRuleParameterEntry[] eRanges = fp.getEnhancementsPolicyRanges(); ObjectScheduleElement element; long start, end; // e.g., min = 0 then start is C + 0 or C - Day of the operation // e.g., min = 1 then start is C + 1 or 2nd day of the operation if (eRanges.length > 0) { start = parentPlugin.getTimeUtils().addNDays(logOPlan.getStartTime(), eRanges[0].getRangeMin()); for (int i = 0; i < eRanges.length; i++) { end = parentPlugin .getTimeUtils() .addNDays(start, (eRanges[i].getRangeMax() - eRanges[i].getRangeMin() + 1)); element = new ObjectScheduleElement(start, end, addEnhancements(new HashMap(), nsns, i, fp)); sched_els.addElement(element); start = end; } } } // else feeding policy is null return empty schedule return parentPlugin.getScheduleUtils().newObjectSchedule(sched_els.elements()); }
protected Schedule getWaterPolicySchedule(FeedingPolicy fp) { Vector sched_els = new Vector(0); if (fp != null) { RangeRuleParameterEntry[] waterRanges = fp.getWaterPolicyRanges(); ObjectScheduleElement element; long start, end; // e.g., min = 0 then start is C + 0 or C - Day of the operation // e.g., min = 1 then start is C + 1 or 2nd day of the operation if (waterRanges.length > 0) { start = parentPlugin .getTimeUtils() .addNDays(logOPlan.getStartTime(), waterRanges[0].getRangeMin()); for (int i = 0; i < waterRanges.length; i++) { end = parentPlugin .getTimeUtils() .addNDays( start, (waterRanges[i].getRangeMax() - waterRanges[i].getRangeMin() + 1)); KeyRuleParameterEntry[] keys = fp.getRangeKeys(waterRanges[i]); element = new ObjectScheduleElement( start, end, addWater(new HashMap(), BOTTLED_WATER, new Double(keys[0].getValue()))); sched_els.addElement(element); start = end; } } } // else feeding policy is null return empty schedule return parentPlugin.getScheduleUtils().newObjectSchedule(sched_els.elements()); }
private KeyRuleParameterEntry[] getActionPolicy(String activity, String optempo) { // This appears to happen sporadically. if (feedingPolicy == null) { if (logger.isErrorEnabled()) { String myOrgName = null; if (parentPlugin != null && parentPlugin.getMyOrg() != null && parentPlugin.getMyOrg().getItemIdentificationPG() != null) myOrgName = parentPlugin.getMyOrg().getItemIdentificationPG().getItemIdentification(); logger.error( "Bug 2982: SubsistenceConsumerBG at Org " + myOrgName + " got null feedingPolicy!", new Throwable()); } return null; } RangeRuleParameterEntry[] rules = feedingPolicy.getRules(); RangeRuleParameter theRule = new RangeRuleParameter(); KeyRuleParameterEntry[] keys; boolean found = false; boolean flag = true; int j = 0; int i = 0; while ((!found) && (i < rules.length)) { theRule = (RangeRuleParameter) rules[i].getValue(); keys = feedingPolicy.getConditionKeys(theRule); j = 0; flag = true; while (flag && (j < keys.length)) { if ((!keys[j].getKey().equalsIgnoreCase("OrgActivity")) && (!keys[j].getKey().equalsIgnoreCase("Optempo"))) { flag = false; } else { if ((!keys[j].getValue().equalsIgnoreCase(activity)) && (!keys[j].getValue().equalsIgnoreCase(optempo))) { flag = false; } } j++; } if (flag) { found = true; } else { i++; } } if (found) { return feedingPolicy.getActionKeys(theRule); } return null; }
public Collection getConsumed() { if (consumedItems == null) { synchronized (cachedDBValues) { Asset asset = myPG.getMei(); if (asset instanceof AggregateAsset) { asset = ((AggregateAsset) asset).getAsset(); } String typeId = asset.getTypeIdentificationPG().getTypeIdentification(); consumedItems = (Collection) cachedDBValues.get(typeId); if (consumedItems == null) { consumedItems = parentPlugin.generateRationList(); if (consumedItems.isEmpty()) { if (logger.isDebugEnabled()) { logger.debug( "getConsumed(): Database query returned EMPTY result set for " + myPG.getMei() + ", " + supplyType); } } else { cachedDBValues.put(typeId, consumedItems); } } } } return consumedItems; }
private HashMap addSupplementRate(HashMap m, String n) { Asset item = parentPlugin.getPrototype(n); if (item != null) { RationPG rpg = (RationPG) item.searchForPropertyGroup(RationPG.class); HashMap supplements = rpg.getMandatorySupplement(); // System.JTEST.out.println (" the supplements list is " + supplements); for (Iterator i = supplements.keySet().iterator(); i.hasNext(); ) { String nsn = (String) i.next(); m = calculateSupplementRate(m, nsn, ((BigDecimal) supplements.get(nsn)).doubleValue()); } // for } // if return m; } // addSupplementRate
protected Schedule getFeedingPolicySchedule(FeedingPolicy fp) { Vector sched_els = new Vector(); ObjectScheduleElement ose; long start, end; ObjectScheduleElement element; Vector mealsSched = createMealAndSupplementSchedule(fp); for (int i = 0; i < mealsSched.size(); i++) { ose = (ObjectScheduleElement) mealsSched.elementAt(i); // e.g., min = 0 then start is C + 0 or C - Day of the operation // e.g., min = 1 then start is C + 1 or 2nd day of the operation start = parentPlugin.getTimeUtils().addNDays(logOPlan.getStartTime(), (int) ose.getStartTime()); end = parentPlugin .getTimeUtils() .addNDays(start, ((int) ose.getEndTime() - (int) ose.getStartTime() + 1)); element = new ObjectScheduleElement(start, end, ose.getObject()); sched_els.addElement(element); start = end; } return parentPlugin.getScheduleUtils().newObjectSchedule(sched_els.elements()); }
public Schedule getParameterSchedule(Collection col, TimeSpan span) { Schedule paramSchedule = null; Vector params = new Vector(); Iterator predList = col.iterator(); UnaryPredicate predicate; // DEBUG // String myOrgName = // parentPlugin.getMyOrg().getItemIdentificationPG().getItemIdentification(); // if (myOrgName.indexOf("35-ARBN") >= 0) { // System.out.println("getParamSched() Asset is "+ // myPG.getMei().getTypeIdentificationPG().getTypeIdentification()); // } ArrayList consumerlist = new ArrayList(); consumerlist.add(myPG.getMei()); Schedule consumerSched = parentPlugin.getScheduleUtils().createConsumerSchedule(consumerlist); consumerSched = parentPlugin.getScheduleUtils().convertQuantitySchedule(consumerSched); params.add(parentPlugin.getScheduleUtils().trimObjectSchedule(consumerSched, span)); while (predList.hasNext()) { Iterator list = ((Collection) predList.next()).iterator(); predicate = (UnaryPredicate) list.next(); if (predicate instanceof OrgActivityPred) { Collection orgColl = (Collection) list.next(); if ((orgColl == null) || (orgColl.isEmpty())) { return null; } Schedule orgActSched = parentPlugin.getScheduleUtils().createOrgActivitySchedule(orgColl); params.add(parentPlugin.getScheduleUtils().trimObjectSchedule(orgActSched, span)); // if (myOrgName.indexOf("35-ARBN") >= 0) { // System.out.println("getParamSched() OrgActSched "+orgActSched); // } } else if (predicate instanceof LogisticsOPlanPredicate) { Collection oplanColl = (Collection) list.next(); if ((oplanColl == null) || (oplanColl.isEmpty())) { return null; } Iterator it = oplanColl.iterator(); if (it.hasNext()) { logOPlan = (LogisticsOPlan) it.next(); } } else if (predicate instanceof FeedingPolicyPred) { Collection fpColl = (Collection) list.next(); if ((fpColl == null) || (fpColl.isEmpty())) { return null; } Iterator it = fpColl.iterator(); Schedule sched; if (it.hasNext()) { feedingPolicy = (FeedingPolicy) it.next(); sched = getFeedingPolicySchedule(feedingPolicy); params.add(parentPlugin.getScheduleUtils().trimObjectSchedule(sched, span)); sched = getEnhancementPolicySchedule(feedingPolicy); params.add(parentPlugin.getScheduleUtils().trimObjectSchedule(sched, span)); sched = getWaterPolicySchedule(feedingPolicy); params.add(parentPlugin.getScheduleUtils().trimObjectSchedule(sched, span)); } } else { if (logger.isErrorEnabled()) { logger.error("getParameterSchedule: unknown predicate " + predicate); } } } paramSchedule = parentPlugin.getScheduleUtils().getMergedSchedule(params); return paramSchedule; }
public void initialize(ClassIConsumerPrototypeProvider plugin) { parentPlugin = plugin; logger = parentPlugin.getLoggingService(this); }
public Rate getRate(Asset asset, List params) { double quantity = 0; // people // CDW if (params.size() < 1) { return null; } // if Object obj = params.get(0); if (obj instanceof Double) { quantity = ((Double) obj).doubleValue(); } else { if (obj != null) { if (logger.isDebugEnabled()) { logger.debug("Bad param - expected quantity got " + obj); } } // if return null; } // if OrgActivity act = null; obj = params.get(1); if (obj instanceof OrgActivity) { act = (OrgActivity) obj; } else { if (obj != null) { if (logger.isDebugEnabled()) { logger.debug("Bad param - expected OrgActivity got " + obj); } } // if return null; } // if KeyRuleParameterEntry[] keys = getActionPolicy(act.getActivityType(), act.getOpTempo()); if ((keys != null) && (keys.length == 0)) { return null; } // if Rate result = null; String identifier = parentPlugin.getAssetUtils().getAssetIdentifier(asset); PackagePG ppg = (PackagePG) asset.searchForPropertyGroup(PackagePG.class); if (ppg == null) { if (logger.isErrorEnabled()) { logger.error("No PackagePG on " + identifier); } } // String type = null; double resource_count = 0; if (keys != null) { for (int j = 0; j < keys.length; j++) { if ((keys[j].getKey().equalsIgnoreCase("Breakfast") && (keys[j].getValue().equals(identifier))) || (keys[j].getKey().equalsIgnoreCase("Lunch") && (keys[j].getValue().equals(identifier))) || (keys[j].getKey().equalsIgnoreCase("Dinner") && (keys[j].getValue().equals(identifier)))) { resource_count += 1.0; } } } else { // keys from getActionPolicy was null // Optempo does not over rule if (params.size() < 3) { if (logger.isErrorEnabled()) { logger.error("Class I ose array in getRate() is missing element " + 2 + " (meal)"); } } else { if (params.get(2) != null) { if (logger.isDebugEnabled()) { logger.debug(" meal params is " + params.get(2) + " resource is " + identifier); } if (((HashMap) params.get(2)).containsKey(identifier)) { // Meals resource_count += ((Double) ((HashMap) params.get(2)).get(identifier)).doubleValue(); if (logger.isDebugEnabled()) { logger.debug(identifier + " rate is " + resource_count); } } // if // DEBUG else { if (logger.isDebugEnabled()) { logger.debug("No meal rates for " + identifier); } } } // if non null params(2) // Enhancements policy if (params.size() >= 4 && params.get(3) != null) { if (((HashMap) params.get(3)).containsKey(identifier)) { // Meals resource_count += ((Double) ((HashMap) params.get(3)).get(identifier)).doubleValue(); if (logger.isDebugEnabled()) { logger.debug( " enhance params is " + ((Double) ((HashMap) params.get(3)).get(identifier)).doubleValue()); } } } } // if have at least thru params(3) } // end of case for null keys // Water if (params.size() < 5) { if (logger.isErrorEnabled()) { logger.error("Class I ose array in getRate() is missing element " + 5 + " water"); } } else { if (params.get(4) != null) { if (((HashMap) params.get(4)).containsKey(identifier)) { // water public static HashMap cachedDBValues = new HashMap(); resource_count += ((Double) ((HashMap) params.get(4)).get(identifier)).doubleValue(); if (logger.isDebugEnabled()) { logger.debug( " water params is " + ((Double) ((HashMap) params.get(4)).get(identifier)).doubleValue()); } } // if } // if } // if if (resource_count > 0) { double total = Math.ceil(resource_count * (1.0 / ppg.getCountPerPack()) * quantity); result = CountRate.newEachesPerDay(total); RationPG rpg = (RationPG) asset.searchForPropertyGroup(RationPG.class); if (logger.isDebugEnabled()) { logger.debug( "\n THE rate is " + CountRate.newEachesPerDay(total) + " for asset " + identifier + " the ration type is " + rpg.getRationType()); } if (logger.isDebugEnabled()) { logger.debug( " Unit of Issue is " + ppg.getUnitOfIssue() + " count per pack" + ppg.getCountPerPack()); } } // if return result; } // getRate