APSF //---------------------------------------------------------------------------------------------- // Resource name to index converters. // function TelescopeIndex(telescopeName as string) as integer dim i as integer for i = 1 to nTelescopes if Telescope(i).Name = telescopeName then return i end if next return 1 end function //------------------------------------------------------------------------------------ // A couple of routines to qualify empty equipment specifications. // function FlagEmpties(s as string) as string if Left(s, 3) = "No " then return "< " + s + " >" else return s end if end function const emptyPrefix = "< No" //---------------------------------------------------------------------------------------------- // Class for recording data. // class equipmentRecord eyepiece as string filter as string aid as string end class //---------------------------------------------------------------------------------------------- // Bucketing classes and routines for histogramming data. // class bucket label as string frequency as integer end class //---------------------------------------------------------------------------------------------- // Sort empty equipment specifications at the bottom. // function CompareLabels(s1 as string, s2 as string) as integer dim prefix1, prefix2 as string prefix1 = Left(s1, Len(emptyPrefix)) prefix2 = Left(s2, Len(emptyPrefix)) if prefix1 = prefix2 then return strcomp(s1, s2, 0) elseif prefix1 = emptyPrefix then return 1 elseif prefix2 = emptyPrefix then return -1 else return strcomp(s1, s2, 0) end if end function //---------------------------------------------------------------------------------------------- // Drop a value into an existing bucket or create a new bucket for it. Buckets are kept // sorted. // sub BucketValue(value as string, buckets() as bucket, byref nBuckets as integer) dim i, j as integer dim b as bucket dim cmp as integer, found as boolean found = false for i = 0 to nBuckets - 1 b = buckets(i) cmp = CompareLabels(value, b.label) if cmp = 0 then found = true b.frequency = b.frequency + 1 exit elseif cmp < 0 then exit end if next if NOT found then b = new bucket b.label = value b.frequency = 1 redim buckets(nBuckets) for j = nBuckets downto i + 1 buckets(j) = buckets(j - 1) next buckets(i) = b nBuckets = nBuckets + 1 end if end sub //---------------------------------------------------------------------------------------------- // Add label, frequency and bar columns to list for a set of buckets. // sub AddBucketsToList(list as integer, buckets() as bucket, nBuckets as integer, colOffset as integer) const INCLUDE_EMPTY_ITEMS = false dim b as bucket dim maxF as integer, pad as string maxF = 0.0001 // avoid div-by-zero for i = 0 to nBuckets - 1 b = buckets(i) if Left(b.label, Len(emptyPrefix)) <> emptyPrefix OR INCLUDE_EMPTY_ITEMS then AddToList(list, i + 1, colOffset, b.label) if b.frequency < 10 then pad = " " elseif b.frequency < 100 then pad = " " else pad = "" end if AddToList(list, i + 1, colOffset + 1, pad + Str(b.frequency)) if b.frequency > maxF then maxF = b.frequency end if end if next // // Generate a poor-man's bar chart // dim factor as double, normalized as integer, j as integer factor = 10 / maxF for i = 0 to nBuckets - 1 b = buckets(i) if Left(b.label, Len(emptyPrefix)) <> emptyPrefix OR INCLUDE_EMPTY_ITEMS then normalized = Round(b.frequency * factor) pad = "" for j = 1 to normalized pad = pad + chr(187) next AddToList(list, i + 1, colOffset + 2, pad) end if next end sub //---------------------------------------------------------------------------------------------- // Main script. // try // Be a good citizen // // Throw up a dialog to see what sites the user wants the report generated from. // const reportOnRadioBtns = "Report On:" const telescopesCheckList = "Used with Telescopes:" dim cancelled as boolean cancelled = false dim current as TelescopeResource, telescopeFlags() as integer, i as integer current = CurrentTelescope if current = nil then current = DefaultTelescope end if redim telescopeFlags(nTelescopes - 1) for i = 1 to nTelescopes if current <> nil AND Telescope(i).Name = current.Name then telescopeFlags(i - 1) = 1 else telescopeFlags(i - 1) = 0 end if next SetCheckListParameter(telescopesCheckList, telescopeFlags, Telescopes) if NOT EditParameters("Equipment Report") then exit end if telescopeFlags = GetCheckListParameter(telescopesCheckList) // // Collect data // StartProgress("Collecting Data...", true, nGlobalObservations) dim records(-1) as equipmentRecord dim nRecords as integer nRecords = 0 dim i as integer, obs as APGlobalObservation dim r as equipmentRecord for i = 1 to nGlobalObservations if UpdateProgress(i) then cancelled = true exit end if obs = GlobalObservation(i) if telescopeFlags(TelescopeIndex(obs.telescope) - 1) = 1 then r = new equipmentRecord r.eyepiece = obs.Eyepiece r.filter = FlagEmpties(obs.Filter) r.aid = FlagEmpties(obs.Aid) redim records(nRecords) records(nRecords) = r nRecords = nRecords + 1 end if next StopProgress() if cancelled then exit // // Histogram data // if nRecords > 500 then StartProgress("Generating Histogram...", true, nRecords) end if dim eyepieceBuckets(-1) as bucket dim nEyepieceBuckets as integer dim filterBuckets(-1) as bucket dim nFilterBuckets as integer dim aidBuckets(-1) as bucket dim nAidBuckets as integer nEyepieceBuckets = 0 nFilterBuckets = 0 nAidBuckets = 0 for i = 0 to nRecords - 1 if nRecords > 500 AND UpdateProgress(i) then cancelled = true exit end if BucketValue(records(i).eyepiece, eyepieceBuckets, nEyepieceBuckets) BucketValue(records(i).filter, filterBuckets, nFilterBuckets) BucketValue(records(i).aid, aidBuckets, nAidBuckets) next if nRecords > 500 then StopProgress() if cancelled then exit end if // // Generate Report // // Generate a coma-delimited list of telescopes for report title dim scopeNames as string, first as boolean first = true for i = 1 to nTelescopes if telescopeFlags(i - 1) = 1 then if NOT first then scopeNames = scopeNames + ", " end if first = false scopeNames = scopeNames + Telescope(i).Name end if next dim list as integer dim reportTitle as string reportTitle = "Equipment Report for " + scopeNames list = NewList(reportTitle) ListHeading(list, 1, "Eyepiece", 3) ListHeading(list, 2, "Frequency", 2) ListHeading(list, 3, "Graph") ListHeading(list, 4, " ") ListHeading(list, 5, "Filter", 3) ListHeading(list, 6, "Frequency", 2) ListHeading(list, 7, "Graph") ListHeading(list, 8, " ") ListHeading(list, 9, "Ovserving Aid", 3) ListHeading(list, 10, "Frequency", 2) ListHeading(list, 11, "Graph") AddBucketsToList(list, eyepieceBuckets, nEyepieceBuckets, 1) AddBucketsToList(list, filterBuckets, nFilterBuckets, 5) AddBucketsToList(list, aidBuckets, nAidBuckets, 9) catch StopProgress() // just in case exception was thrown during data collection print "My bad. Equipment Report script generated an exception." end try