Lunarpedia talk:Autostub1

From Lunarpedia
Revision as of 13:44, 17 January 2007 by Cfrjlr (talk | contribs) (→‎Software Development Plan: please clarify)
Jump to: navigation, search

Software Development Plan

Thanks for the responses to my various questions. Essentially what I would like to see here is a detailed requirements specification and/or a detailed design document. that will address your valid concerns that "we need to get it right first time"...

In my experience, the most common and most devastating problem encountered by software development projects is.... screwed up requirements, ie requirements which are vague, ambiguous, confusing, misleading, impossible, contradictory, meaningless, non-sensical, and/or incomplete, or just plain wrong. So that is why I am asking lots of questions to make sure the requirements are crystal clear, and we know exactly what we are trying to achieve before we go zooming up the wrong road.

Thanks.


Charles F. Radley 19:41, 16 January 2007 (PST)

Thank you for pointing out this blazingly obvious point that mysteriously never occurred to me. In my defense, I've been working on an iterative development concept (at least until I got detoured) that is compatible with cranking out something now and getting a clue later (even if it means scrapping or shelving a lot of code in the process).
How confusing is my internal documentation? A historical complaint is that my commenting has often been less than fully helpful.
This probably requires its own page, as we're moving beyond the first test. How about Lunarpedia:Autostub1 (...which already exists -- I forgot all about it)?
-- Strangelv 01:41, 17 January 2007 (PST)


Sector areas code:Set up variables to generate article stub Are we ready to incorporate the equations for sector area into the script? Charles F. Radley

Sector Areas could be precomputed and referenced by latitude, as there's basically only five or so different areas unless we want to get really serious and go by actual complex geometry instead of treating it as a sphere (or for partial bonus credit, a slightly flattened sphere) (for example, I've been told that Earth is slightly pear shaped).
Presumably the computation or selection of area could be added to 'Set up variables to generate article stub' and then added to the template graphics below that before to_out is run through tidypipes(), as required by {{Circular Feature}}.
--Strangelv 01:41, 17 January 2007 (PST)
James, what do you mean by "five or so different areas " ? Do you mean there are only 5 sectors?
The solution I posted assumes the Moon is a perfect sphere, for our purposes there is no reason to use more ellaborate models. I believe the equations I provided are adequate. We are not trying to perform a pinpoint landing of a spacecraft, nor make topographic measurements, we are only giving the users some visual experience.
Please provide the lattitude/longitude boundaries of each sector and I will calculate the area by hand. Where do you want me to put the results?
Charles F. Radley 05:02, 17 January 2007 (PST)
24 sectors along the equator have the same area; 2 polar sectors have the same area; all other sectors share the same area with 47 other sectors. Sorry if 'area' is a confusing term to use here. -- Strangelv 06:21, 17 January 2007 (PST)
For what area each sector is, the latitude boundaries are irrelevant. There's 24 equally sized ones at any latitude between 7.5 N and 7.5 S, unless we tinker with the definition -- which there's still time to do. Wait, that's the longitude boundaries. 7.5 N to 7.5 S, then 22.5 N to 22.5 S, et c. until...
*Strangelv reaches for the semicolon to do some arithmatic with he's too groggy to do in his head
;90.0-7.5
=> 82.5
You say, "82.5N -- mirrored for the southern hemisphere. All equatorial sectors have the same area unless we do a highly precise model. Ditto the ones above and below the equator, then the ones above and below them, et c.
-- Strangelv 06:52, 17 January 2007 (PST)

James, sorry but I do not understand what you wrote there, and I re-read it a couple of times. It is a case of an incomprehensible requirement :-)

What I need is this:

List of areas (sectors), and for each area (sector) specify the following four values:

- Latitude of Northern boundary
- Latitude of Southern boundary
- Longitude of Western Boundary
- Longitude of Eastern Boundary

Give me that list of parameters and I will tell you what the area is of each sector.

Thanks.

Charles F. Radley 13:44, 17 January 2007 (PST)

Specifications

The specifications are a mixture of what has been done, what I've forgotten I wanted to do, what I thought of on the fly. It's a real mess right now, but may be a workable starting point for discussion. -- Strangelv 06:09, 17 January 2007 (PST)

Software Requirements Specification

Software Design Specification

Software Test Plan

Code

Tinker here.


#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#
#                             #
# Feature Autostub Generator  #
#                             #
# Licence pending             #
#                             #
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#

def dostub(thisentry):
    """Create stub article from database
    """
    #   
    # Set up variables to generate article stub
    #
    #%#%#%#%#%#%#%#%#%#%#%#%#%#%%#%#%#%#%#
                                         #
    name = thisentry[2]                  # name of feature
    mapname = makemapname(name, None)    # filename for this feature's
                                         #      automatically generated
                                         #      map from Clementine data
    Lat = float(thisentry[3])            # USGS latitude
    lat = do_lat(Lat)                    # string with proper latitude
    me_long = poslong(thisentry[4])      # longitude (Mean Earth)
    mo_long = me2mo(me_long)             # longitude (Mare Orientale)
    me_coord = coordstr(me_long, lat)    # Mean Earth coordinate string
    mo_coord = coordstr(mo_long, lat)    # Mare Orientale coordinate string
    origin = thisentry[24]               # 'Origin' column in database
                                         #          warning: this seems to
                                         #          be almost anything
    featuretype = thisentry[23]          # Is this a mare, a crater, other?
    dia = thisentry[10]                  # feature diameter, if applicable
    approvalStat = thisentry[18]         # year approval information
    approvalYear = thisentry[19]         # year of approval (if approved)
    reference = thisentry[21]            # 'reference' column in database
    inSector = isinsector(mo_long, Lat)  # what sector is this feature
                                         #      centered in?
    sectors = sectorlist(mo_long, lat, dia)
                                         # -----what sectors include it?
    typecat = dotypecat(featuretype)     # simplified category type
    domap(mapname, mo_long, lat, dia)    # create the map
    localeDescr = descrlocale(mo_long, Lat, typecat)
                                         # -----text description of location
    approvalStr = doapproval(approvalStat, approvalYear)
                                         # -----text description of approval,
                                         #      if approved.
    #%#%#%#%#%#%#%#%#%#%#%#%#%#%%#%#%#%#%#
    #
    # start generating the article here:
    #
    to_out  = []
    to_out += ["{"+"{Circular Feature "]
    to_out += ["name        = "+name]
    to_out += ["featuretype = "+typecat]
    to_out += ["origin      = "+origin]
    to_out += ["map         = [[Image:"+mapname+"|240px]]"]
    to_out += ["mo_coord    = "+mo_coord]
    to_out += ["me_coord    = "+me_coord]
    to_out += ["dia         = "+dia]
    to_out += ["approval    = "+approvalStr]
    
    # Tidily install pipes for the table 
    to_out = tidypipes(to_out)
    
    to_out += ["}"+"}"]
    to_out += ["'''"+name+"''' "+localeDescr]
    to_out += ["<BR/><BR/>\n\n"]
    # if inSector !="AAAAAAAAA!":
    to_out += ["The center of "+name+" is in sector [[Sector_"+inSector+"]]"]
    # else:
    #      inSectors = something()
    to_out += ["<BR/><BR/>\n\n"]
    to_out += ["==See Also=="]

    for q in sectors:
        to_out += ["[["+q+"]]"]
    
    to_out += ["<BR/><BR/>\n\n"]
    to_out += ["==References=="]
    to_out += [refbreak(reference)]
    to_out += ["{"+"{Autostub}"+"}"]
    # to_out += ["[[Category:Locations]]"]
    to_out += docategories(typecat) #["[[Category:"+typecat+"]]"]
    to_out += ["<!-- Generated by a too-early version of WikiMess Autostub1 -->"]

    return to_out




# def main():
#     # load database
#     didxml = templatetop()
#     for q in database: didxml += dostub(q) + templatemid(); print ".",
#     didxml += templatefin()
#     # save didxml

def makemapname(name, other):
    """
    """
    name2=""
    for q in name:
        if q == " ": name2 += "_"
        else: name2 += q
    if other: name2 += "_"+other
    name2 += ".png"
    return name2

def poslong(long_):
    """convert string of possibly noncompliant Mean Earth longitude into float or fixed of compliant Mean Earth longitude
    """
    long_ = float(long_)
    if long_ < 0 : long_ += 360
    return long_

def me2mo(me_long):
    """
    """
    mo_long=float(me_long)-267.2
    if mo_long <0: mo_long += 360.0
    #print "me_long == "+str(me_long)
    return mo_long

def coordstr(long_,lat):
    """ temporary implementation
    """
    return str(lat)+" "+str(long_)

def descrlocale(long_, lat, what):
    """quickie hack
    """
    if   lat > 5: vert = "a northern"
    elif lat < 5: vert = "a southern"
    else: vert = "an equitorial"

    if   long_ <= 165 and long_ >= 15: side = "near side"
    elif long_ <= 195 and long_ >= 345: side = "far side"
    elif long_ >= 165 and long_ <= 195: side = "east edge"
    else: side = "west edge"
    
    return "is "+vert+" "+what+" on the "+side+" of Luna."

def isinsector(long_,lat):
    """can we determinewhat sector you're in?
    """
    # special case handling?
    def AAAAAAAAA():
        # border case handling
        return "AAAAAAAAA!"
    # find latitude part or bust
    if lat == 0.0: LT="E" # this is equatorial
    else:
         if lat > 0: LTH = "N"
         else:
              lat = -lat
              LTH = "S"
         if ((lat+7.5)//15) == ((lat+7.5)/15.0): return AAAAAAAAA()
         LT = str(int(((lat+7.5)//15)*15)) + LTH
         if LT == "90": return LTH # this is a polar sector
    # find longitude part or bust
    if long_ < 7.5 or long_ > 352.5: LG = "000" # prime meridian sector
    else:
         if ((long_+7.5)//15) == ((long_+7.5)/15.0): return AAAAAAAAA()
         LG = str(int(((long_+7.5)//15)*15))
         if len(LG)<3: LG = "0"+LG
    # return the result!
    return LT+LG

def dotypecat(stringie):
    """
    """
    if stringie == "Rima, rimae": return "rima"
    # Most definitely need to list the complete set
    return stringie

def docategories(typecat):
    if typecat == "rima": return ["[[Category:Rima]]","[[Category:Locations]]"]
    return [typecat]

def sectorlist(long_,lat,dia):
    """
    """
    return ["sectorlist() not implemented"]

def domap(mapname,long_,lat,dia):
    """
    """
    return "domap() not implemented"

def doapproval(approvalStat, approvalYear):
    """temporary hack; needs to acconut for unapproved
    """
    return approvalStat+" in "+approvalYear

def tidypipes(table):
    """takes a list oy strings, finds the longest one, and tidily adds pipes to the right of each line.

    maxlen: maximum length
    table:  input list of strings
    table2: output list of strings
    """
    maxlen = 0
    for q in table:
        if len(q)>maxlen: maxlen = len(q)
    table2 = []
    for q in table:
        qq = q
        while (len(qq)<maxlen):
              qq += " "
        table2 += [qq+" |"]
    return table2

def do_lat(lat):
    """returns string for latitude
    """
    if lat > 0: return str(lat)+"N"
    if lat == 0: return "E"
    return str(-lat)+"S"

def replacer(stringie, old, new):
    """
    """
    name2=""
    for q in stringie:
        if q == old: name2 += new
        else: name2 += q
    return name2

def refbreak(ref):
    """
    """
    return replacer(ref,";",";<BR/>")


##def ():
##    """
##    """
##    return "() not implemented"
##
##def ():
##    """
##    """
##    return "() not implemented"


#Item = ["Earth","Moon","Rima Diophantus","29.0","-33.0"," "," "," "," ","east","150.0","EU","Europe","GR","Greek","LTO39B2","LTO-39B2","5","Adopted by IAU","1985","0","null","RI","Rima, rimae","Named from nearby crater."]
Item = ["Earth","Moon","Rima Cardanus","11.4","-71.5"," "," "," "," ","east","175.0","EU","Europe","IT","Italy","LOC-1","LOC-1","5","Adopted by IAU","1964","67","The System of Lunar Craters, Quadrants I, II, III, IV; by D. W. G. Arthur and others; Communications of the Lunar and Planetary Laboratory, vol. 2, no. 30, 1963; vol. 3, no. 40, 1964; vol. 3, no. 50, 1965; vol. 5, no. 70, 1966.","RI","Rima, rimae","Named from nearby crater."]

What=dostub(Item)
for q in What: print q