def hazardBodyText(self, hazardList, argDict): hazardBodyPhrase = '' # # First, sort the hazards for this segment by importance # sortedHazardList = [] for each in ['W', 'Y', 'A', 'S']: for eachHazard in hazardList: if eachHazard['sig'] == each: if eachHazard not in sortedHazardList: sortedHazardList.append(eachHazard) # # Next, break them into individual lists based on action # newList = [] canList = [] expList = [] extList = [] conList = [] upgList = [] statementList = [] for eachHazard in sortedHazardList: if eachHazard['act'] in ['NEW', 'EXA', 'EXB'] and \ eachHazard['sig'] != 'S': newList.append(eachHazard) elif eachHazard['act'] in ['CAN'] and eachHazard['sig'] != 'S': canList.append(eachHazard) elif eachHazard['act'] in ['EXP'] and eachHazard['sig'] != 'S': expList.append(eachHazard) elif eachHazard['act'] in ['EXT'] and eachHazard['sig'] != 'S': extList.append(eachHazard) elif eachHazard['act'] in ['UPG'] and eachHazard['sig'] != 'S': upgList.append(eachHazard) elif eachHazard['sig'] != 'S': conList.append(eachHazard) elif eachHazard['sig'] == 'S': statementList.append(eachHazard) # # Now, go through each list and build the phrases # nwsIntroUsed = 0 # # This is for the new hazards # phraseCount = 0 for eachHazard in newList: if len(eachHazard['hdln']) == 0: continue #no defined headline, skip phrase endTimePhrase = self.hazardTimePhrases(eachHazard, argDict) hazNameA = self.hazardName(eachHazard['hdln'], argDict, True) hazName = self.hazardName(eachHazard['hdln'], argDict, False) # OVERRIDES Dave Metze Shannon White 10/10/08 if hazName == "WINTER WEATHER ADVISORY" or hazName == "WINTER STORM WARNING": forPhrase = " FOR |* ENTER HAZARD TYPE *|" else: forPhrase ="" if nwsIntroUsed == 0: hazardBodyPhrase = "THE NATIONAL WEATHER SERVICE IN " + self._wfoCity nwsIntroUsed = 1 if phraseCount == 0: phraseCount = 1 hazardBodyPhrase = hazardBodyPhrase + " HAS ISSUED " + \ hazNameA + forPhrase + \ "...WHICH IS IN EFFECT" + endTimePhrase + ". " elif phraseCount == 1: phraseCount = 2 hazardBodyPhrase = hazardBodyPhrase + hazNameA + \ " HAS ALSO BEEN ISSUED. THIS " + hazName + \ forPhrase + " IS IN EFFECT" + endTimePhrase + ". " else: hazardBodyPhrase = hazardBodyPhrase + "IN ADDITION..." + \ hazNameA + forPhrase + " HAS BEEN ISSUED. THIS " + hazName + \ " IS IN EFFECT" + endTimePhrase + ". " # OVERRIDES END # # This is for the can hazards # for eachHazard in canList: if len(eachHazard['hdln']) == 0: continue #no defined headline, skip phrase hazName = self.hazardName(eachHazard['hdln'], argDict, False) if nwsIntroUsed == 0: hazardBodyPhrase = "THE NATIONAL WEATHER SERVICE IN " +\ self._wfoCity nwsIntroUsed = 1 hazardBodyPhrase = hazardBodyPhrase + \ " HAS CANCELLED THE " + hazName + ". " else: hazardBodyPhrase = hazardBodyPhrase + "THE " + hazName + \ " HAS BEEN CANCELLED. " # # This is for the exp hazards # phraseCount = 0 for eachHazard in expList: if len(eachHazard['hdln']) == 0: continue #no defined headline, skip phrase hazName = self.hazardName(eachHazard['hdln'], argDict, False) if eachHazard['end'] <= argDict['creationTime']: hazardBodyPhrase = hazardBodyPhrase + "THE " + hazName + \ " IS NO LONGER IN EFFECT. " else: expTimeCurrent = argDict['creationTime'] timeWords = self.getTimingPhrase(eachHazard, expTimeCurrent) hazardBodyPhrase = hazardBodyPhrase + "THE " + hazName + \ " WILL EXPIRE " + timeWords + ". " # # This is for ext hazards # for eachHazard in extList: if len(eachHazard['hdln']) == 0: continue #no defined headline, skip phrase endTimePhrase = self.hazardTimePhrases(eachHazard, argDict) hazName = self.hazardName(eachHazard['hdln'], argDict, False) hazardBodyPhrase = hazardBodyPhrase + "THE " + hazName + \ " IS NOW IN EFFECT" + endTimePhrase + ". " # # This is for upgrade hazards # for eachHazard in upgList: if len(eachHazard['hdln']) == 0: continue #no defined headline, skip phrase hazName = self.hazardName(eachHazard['hdln'], argDict, False) hazardBodyPhrase = hazardBodyPhrase + "THE " + hazName + \ " IS NO LONGER IN EFFECT. " # # This is for con hazards # for eachHazard in conList: if len(eachHazard['hdln']) == 0: continue #no defined headline, skip phrase endTimePhrase = self.hazardTimePhrases(eachHazard, argDict) hazNameA = self.hazardName(eachHazard['hdln'], argDict, True) hazardBodyPhrase = hazardBodyPhrase + hazNameA + \ " REMAINS IN EFFECT" + endTimePhrase + ". " # # This is for statement hazards # #we will add in text later either by text capture or #framing codes as needed #for eachHazard in statementList: # hazardBodyPhrase = hazardBodyPhrase + "|* STATEMENT TEXT *|." # # This adds segment text # segmentText = '' # # Check that this segment codes to determine capture or not, # and frame captured text or not # incTextFlag, incFramingCodes, skipCTAs, forceCTAList = \ self.useCaptureText(sortedHazardList) # # # Check that the previous text exists # foundCTAs = [] for eachHazard in sortedHazardList: if eachHazard.has_key('prevText'): prevText = eachHazard['prevText'] if eachHazard['sig'] == 'S': startPara = 0 else: startPara = 2 segmentText, foundCTAs = self.cleanCapturedText(prevText, startPara, addFramingCodes = incFramingCodes, skipCTAs = skipCTAs) # # Check that the segment text isn't very short or blank # if len(segmentText) < 6: incTextFlag = 0 # # If segment passes the above checks, add the text # if incTextFlag: hazardBodyPhrase = hazardBodyPhrase + "\n\n" + \ segmentText + '\n\n' # If segment doesn't pass the checks, put in framing codes else: if eachHazard['sig'] != 'S': hazardBodyPhrase = hazardBodyPhrase + \ "\n\n|* SEGMENT TEXT GOES HERE *|.\n\n" else: hazardBodyPhrase = hazardBodyPhrase + \ "\n\n|* STATEMENT TEXT GOES HERE *|.\n\n" # # This adds the call to action statements. This is only performed # if the segment is 'NEW' or if the previous text has been discarded # due to a CAN/EXP/UPG segment # # remove items from forceCTAList if they exist in foundCTAs. Note # that the formats of these lists are different, thus this code # is more complicated for ent in foundCTAs: #only process CTAs that are vtec phen/sig based if ent.find('.') == 2: phensig = (ent[0:2], ent[3]) #phen.sig if phensig in forceCTAList: del forceCTAList[forceCTAList.index(phensig)] hazardBodyPhrase = hazardBodyPhrase + '\n\n' ctas = [] for (phen,sig) in forceCTAList: hazardPhenSig = phen + "." + sig cta = self.defaultCTA(hazardPhenSig) if cta not in ctas: ctas.append(cta) for c in ctas: hazardBodyPhrase = hazardBodyPhrase + c + '\n\n' return hazardBodyPhrase