Featured Lakes of a Map Book

14 Jul

A map that displays featured lakes and the attributes that are important to know for fishing. All of these maps were produces via a Python Script.

from os import walk
import csv

def handle_fish_presence(csvFilePath):
    info = []
    with open(csvFilePath) as csvFile:
        reader = csv.reader(csvFile)
        
        for fish in reader:
            fish_type = fish[0]
            if fish_type != 'SPECIES_NAME':
                info.append(fish_type)
        #print info
    return info

def handle_lake_access(csvFilePath):
    info = []
    with open(csvFilePath) as csvFile:
        reader = csv.reader(csvFile)
        
        for access in reader:
            access_type = access[0]
            if access_type != 'DESCRIPTION':
                info.append(access_type)
        #print info
    return info

def handle_land_uses(csvFilePath):
    info = []
    with open(csvFilePath) as csvFile:    
        reader = csv.reader(csvFile)
        
        for row in reader:
            row_value = row[0]
            if row_value != 'DESCRIPTION':
                info.append(row_value)    
        #print info
    return info

def handle_lake_facility(csvFilePath):
    info = []
    with open(csvFilePath) as csvFile:    
        reader = csv.reader(csvFile)
        
        for row in reader:
            row_value = row[0]
            if row_value != 'DESCRIPTION':
                info.append(row_value)     
        #print info
    return info

def handle_stocking_info(csvFilePath):
    with open(csvFilePath) as csvFile:
        reader = csv.reader(csvFile)
        
        for row in reader:
            row_value = row[0]
            if row_value != "RELEASE_DATE":
                year = row[0].split("-")[0]
                species = row[1]
                info = [year, species]
                break
        #print info
    return info

def handle_site_survey_info(csvFilePath):
    with open(csvFilePath) as csvFile:
        reader = csv.reader(csvFile)
        for row in reader:
            #print row
            row_value = row[0]
            if row_value != "SURVEY_DATE":
                survey_date = row[0]
                year = survey_date.split("-")[2]
                season = row[5]
                info = [year, season]   
                break
    
        #print info
    return info

lake_dir_names = ['00026STHM', '00072STHM', '00350STHM', '00439NICL', '00604STHM', '00866STHM', '00926STHM', '00987SHUL', '01005NICL', '01104SHUL', '01189STHM', '01272NICL', '01451NICL', '01500NICL', '01506NICL', '01982NICL']
lakereportmap = {}

for lakeID in lake_dir_names:
    #print "Processing: " + lakeID
    
    dirpath = "..\\inputs\\lakeInfo\\" + lakeID
    for (lake_dirpath, lake_dirnames, lake_filenames) in walk(dirpath):
        #print "Lake Files: " + str(lake_filenames)
        #print "Lake Dirpath: " + str(lake_dirpath)
        
        lake_info = {}
        
        for lake_filename in lake_filenames:
            csvFile = lake_dirpath + "\\" + lake_filename
            #print "LakeID: " + str(lakeID)
            #print "csvFile: " + csvFile
            
            typeFile = lake_filename.split("-")[0]
            #print 
            #print 
            #print "Type of analysis: " + typeFile

            if typeFile == "FishPresence":
                lake_info['FishPresence'] = handle_fish_presence(csvFile) 
            elif typeFile == "LakeAccessInfo":
                lake_info['LakeAccessInfo'] = handle_lake_access(csvFile)
            elif typeFile == "LandUses":
                lake_info['LandUses'] = handle_land_uses(csvFile)
            elif typeFile == "SiteSurveyLakeInformation":
                lake_info['SiteSurvey'] = handle_site_survey_info(csvFile)
            elif typeFile == "LakeFacilityInfo":
                lake_info['LakeFacility'] = handle_lake_facility(csvFile)
            elif typeFile == "StockingInformation":
                lake_info['StockingInformation'] = handle_stocking_info(csvFile)
        
        lakeReport = ''
        bHasFish = lake_info.has_key('FishPresence')
        bIsStocked = lake_info.has_key('StockingInformation')
        bHasFacilities = lake_info.has_key('LakeFacility')
        bHasAccess = lake_info.has_key('LakeAccessInfo')
        bLandUses = lake_info.has_key('LandUses')
        bWasSurveyed = lake_info.has_key('SiteSurvey')
        
       
        bHasInfo = False
        
        if bHasFish:
            bHasInfo = True
            lakeReport = 'The lake has '
            if bIsStocked:
                lakeReport += 'plentiful numbers of '
            num_of_fish = len(lake_info['FishPresence'])
            
            for fish_idx in range(0, num_of_fish - 2):
                if fish_idx == (num_of_fish - 3):
                    lakeReport = lakeReport + lake_info['FishPresence'][fish_idx] + ' and '
                else:
                    lakeReport = lakeReport + lake_info['FishPresence'][fish_idx] + ", "
                    
            lakeReport += lake_info['FishPresence'][num_of_fish - 1]
            
            if bIsStocked == False:
                lakeReport += " that are naturally repopulating" 
            lakeReport += "."
            
        if bHasAccess:
            bHasInfo = True
            lakeReport += 'The lake is accessible by road.'
        
        if bHasFacilities:
            bHasInfo = True
            lakeReport += 'The lake has access to facilities. These include '
            num_of_facilities = len(lake_info['LakeFacility'])
            for facility_idx in range(0, num_of_facilities - 2):
                lakeReport = lakeReport + lake_info['LakeFacility'][facility_idx] + ", "
            lakeReport += lake_info['LakeFacility'][num_of_facilities -1]
            lakeReport += '. '
        
        if bLandUses:
            bHasInfo = True
            lakeReport += 'The land around the lake is used for '
            num_of_land = len(lake_info['LandUses'])
            for land_idx in range(0, num_of_land - 2):
                lakeReport = lakeReport + lake_info['LandUses'][land_idx] + ", "
            lakeReport += lake_info['LandUses'][num_of_land -1]
            lakeReport += '. '
            
        if bWasSurveyed:
            bHasInfo = True
            lakeReport += 'The lake was last surveyed in the ' + lake_info['SiteSurvey'][1] + ' of ' + lake_info['SiteSurvey'][0] + '.'
    
        if bHasInfo == False:
            lakeReport += 'This lake is a total mystery that only Scooby and the Gang can solve!'

        lakereportmap[lakeID] = lakeReport
        #print 'Lake Report for ' + str(lakeID)
        #print lakeReport
        
for lake in lakereportmap:
    print str(lake)
    print lakereportmap[lake]
    print