Difference between revisions of "Lunarpedia talk:Autostub1 test 1"

From Lunarpedia
Jump to: navigation, search
(→‎Software Development Plan: what do you mean by "five or so different areas " ?)
(→‎Source Code: upgraded to what should be the most recent version)
 
(2 intermediate revisions by the same user not shown)
Line 53: Line 53:
  
 
==Software Development Plan==
 
==Software Development Plan==
 +
Moved to [[Lunarpedia_talk:Autostub1#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 wrongSo 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.
+
==Source Code==
 +
Warning: Put in place with <PRE> tags, which change some formattingCopy from the edit or view source page to get an accurate copy.
  
Thanks.
+
And yes, the code is really rough in a few places (like where reinventing the wheel is faster than remembering where the wheel is).  The language is Python.  2.4 and later should work; earlier may require replacing my '//' division with integer coercion.
  
 +
<PRE>
 +
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#
 +
#                            #
 +
# Autostub 1                  #
 +
#                            #
 +
# Feature Autostub Generator  #
 +
#                            #
 +
# Public Domain              #
 +
#                            #
 +
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#
  
[[User:Cfrjlr|Charles F. Radley]] 19:41, 16 January 2007 (PST)
+
def dofeature(thisentry):
 
+
    """Generates article on a feature given in thisentry
: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).
+
     
 
+
                00 -- system (will always be 'Earth'
:How confusing is my internal documentation?  A historical complaint is that my commenting has often been less than fully helpful.
+
                01 -- satellite (will always be Moon)
 
+
    name        02 -- name
: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)?
+
    lat          03 -- USGS latitude
 
+
                04 -- USGS longitude
:-- [[User:Strangelv|Strangelv]] 01:41, 17 January 2007 (PST)
+
    me_long = poslong(thisentry[4])  -- Mean Earth longitude
 
+
    mo_long = me2mo(me_long)          -- Mare Orientale longitude
 
+
    me_coord = coordstr(me_long, lat) -- string for Mean Earth coordinates
Sector areas code:Set up variables to generate article stub
+
    mo_coord = coordstr(mo_long, lat) -- string for Mare Orientale coordinates
Are we ready to incorporate the equations for sector area into the script?
+
                05 -- starting latitude (never provided, unfortunately)
[[User:Cfrjlr|Charles F. Radley]]
+
                06 -- ending latitude (never provided, unfortunately)
 
+
                07 -- starting longitude (never provided, unfortunately)
: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).
+
                08 -- ending longitude (never provided, unfortunately)   
 
+
                09 -- DIR (???)
: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 '''{<B></B>{Circular Feature}<B></B>}'''.
+
    dia          10 -- diameter in klicks
 
+
                11 -- CT (country of discovery?)
:--[[User:Strangelv|Strangelv]] 01:41, 17 January 2007 (PST)
+
                12 -- Continent (of discovery?)
 +
                13 -- ET (???)
 +
                14 -- Ethnicity (of name?)
 +
                15 -- Quad (USGS map info)
 +
                16 -- Map (USGS map info)
 +
                17 -- AS (???)
 +
    approvalStat 18 -- Approved Status Description
 +
    approvalYear 19 -- Approval Date (year)
 +
                20 -- REF (???)
 +
    reference    21 -- References
 +
                22 -- FT (Feature Type categorization, presumably)
 +
    featuretype  23 -- Feature Type Name
 +
    origin      24 -- origin
 +
   
 +
   
 +
    """
  
James, what do you mean by "five or so different areas " ? Do you mean there are only 5 sectors?
+
    # 
 +
    # 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=="]
  
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.
+
    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 -->"]
  
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?
+
    return to_out
  
[[User:Cfrjlr|Charles F. Radley]] 05:02, 17 January 2007 (PST)
 
  
  
==Software Requirements Specification==
 
  
==Software Design Specification==
+
# def main():
 +
#    # load database
 +
#    didxml = templatetop()
 +
#    for q in database: didxml += dostub(q) + templatemid(); print ".",
 +
#    didxml += templatefin()
 +
#    # save didxml
  
==Software Test Plan==
+
def makemapname(name, other):
 +
    """
 +
    """
 +
    name2=""
 +
    for q in name:
 +
        if q == " ": name2 += "_"
 +
        else: name2 += q
 +
    if other: name2 += "_"+other
 +
    name2 += ".png"
 +
    return name2
  
==Source Code==
+
def poslong(long_):
Warning: this was getting mauled in a few places.  I've tinkered with the formatting to make it work.
+
    """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_
  
And yes, the code is really rough in a few places (like where reinventing the wheel is faster than remembering where the wheel is). The language is Python.  2.4 and later should work; earlier may require replacing my '//' division with integer coercion.
+
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
  # Feature Autostub Generator  #
+
    """
  #                            #
+
    return str(lat)+" "+str(long_)
  # Licence pending            #
 
  #                            #
 
  #%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#
 
  
  def dostub(thisentry):
+
def descrlocale(long_, lat, what):
      """Create stub article from database
+
     """quickie hack
      """
+
    """
      # 
+
    if  lat > 5: vert = "a northern"
      # Set up variables to generate article stub
+
    elif lat < 5: vert = "a southern"
      #
+
    else: vert = "an equatorial"
      #%#%#%#%#%#%#%#%#%#%#%#%#%#%%#%#%#%#%#
 
                                          #
 
      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        = [<B></B>[Image:"+mapname+"|240px]<B></B>]"]
 
      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 += ["'<B></B>'<B></B>'"+name+"'<B></B>'<B></B>' "+localeDescr]
 
      to_out += ["<<B></B>BR/><<B></B>BR/>\n\n"]
 
      # if inSector !="AAAAAAAAA!":
 
      to_out += ["The center of "+name+" is in sector [<B></B>[Sector_"+inSector+"]<B></B>]"]
 
      # else:
 
      #      inSectors = something()
 
      to_out += ["<<B></B>BR/><<B></B>BR/>\n\n"]
 
      to_out += ["==See Also=="]
 
  
      for q in sectors:
+
    if  long_ <= 165 and long_ >= 15: side = "near side"
          to_out += ["[<B></B>["+q+"]<B></B>]"]
+
    elif long_ <= 195 and long_ >= 345: side = "far side"
     
+
    elif long_ >= 165 and long_ <= 195: side = "east edge"
      to_out += ["<<B></B>BR/><<B></B>BR/>\n\n"]
+
    else: side = "west edge"
      to_out += ["==References=="]
+
   
      to_out += [refbreak(reference)]
+
    return "is "+vert+" "+what+" on the "+side+" of Luna."
      to_out += ["{<B></B>{Autostub}<B></B>}"]
 
      to_out += ["[<B></B>[Category:Location]<B></B>]"]
 
      to_out += ["[<B></B>[Category:"+typecat+"]<B></B>]"]
 
      to_out += ["<!-- Generated by a too-early version of WikiMess Autostub1 -->"]
 
  
      return to_out
+
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 main():
+
def domap(mapname,long_,lat,dia):
  #     # load database
+
     """
  #     didxml = templatetop()
+
     """
  #    for q in database: didxml += dostub(q) + templatemid(); print ".",
+
     return "domap() not implemented"
  #     didxml += templatefin()
 
  #    # save didxml
 
  
  def makemapname(name, other):
+
def doapproval(approvalStat, approvalYear):
      """
+
    """temporary hack; needs to acconut for unapproved
      """
+
    """
      name2=""
+
    return approvalStat+" in "+approvalYear
      for q in name:
 
          if q == " ": name2 += "_"
 
          else: name2 += q
 
      if other: name2 += "_"+other
 
      name2 += ".png"
 
      return name2
 
  
  def poslong(long_):
+
def tidypipes(table):
      """convert string of possibly noncompliant Mean Earth longitude into float or fixed of compliant Mean Earth longitude
+
    """takes a list oy strings, finds the longest one, and tidily adds pipes to the right of each line.
      """
 
      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 equatorial"
 
 
 
      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):
+
    maxlen: maximum length
      """can we determinewhat sector you're in?
+
    table:  input list of strings
      """
+
    table2: output list of strings
      # special case handling?
+
    """
      def AAAAAAAAA():
+
    maxlen = 0
          # border case handling
+
    for q in table:
          return "AAAAAAAAA!"
+
        if len(q)>maxlen: maxlen = len(q)
      # find latitude part or bust
+
    table2 = []
      if lat == 0.0: LT="E" # this is equatorial
+
    for q in table:
      else:
+
        qq = q
          if lat > 0: LTH = "N"
+
        while (len(qq)<maxlen):
          else:
+
              qq += " "
                lat = -lat
+
        table2 += [qq+" |"]
                LTH = "S"
+
    return table2
          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):
+
def do_lat(lat):
      """
+
    """returns string for latitude
      """
+
    """
      if stringie == "Rima, rimae": return "rima"
+
    if lat > 0: return str(lat)+"N"
      # Most definitely need to list the complete set
+
    if lat == 0: return "E"
      return stringie
+
    return str(-lat)+"S"
  
  def sectorlist(long_,lat,dia):
+
def replacer(stringie, old, new):
      """
+
    """
      """
+
    """
      return ["sectorlist() not implemented"]
+
    name2=""
 +
    for q in stringie:
 +
        if q == old: name2 += new
 +
        else: name2 += q
 +
    return name2
  
  def domap(mapname,long_,lat,dia):
+
def refbreak(ref):
      """
+
    """
      """
+
    """
      return "domap() not implemented"
+
    return replacer(ref,";",";<BR/>")
  
  def doapproval(approvalStat, approvalYear):
 
      """temporary hack; needs to acconut for unapproved
 
      """
 
      return approvalStat+" in "+approvalYear
 
  
  def tidypipes(table):
+
##def ():
      """takes a list oy strings, finds the longest one, and tidily adds pipes to the right of each line.
+
##    """
 +
##    """
 +
##    return "() not implemented"
 +
##
 +
##def ():
 +
##    """
 +
##    """
 +
##    return "() not implemented"
  
      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):
+
def Stringify(listish):
      """returns string for latitude
+
    stringish = ""  
      """
+
    for q in listish:
      if lat > 0: return str(lat)+"N"
+
        if type(q) == type('str'):
      if lat == 0: return "E"
+
          stringish += q
      return str(-lat)+"S"
+
          #print "str"
 +
        elif type(q) == type([]):
 +
          stringish += Stringify(q)
 +
          #print "list"
 +
        else:
 +
            print type(q)
 +
            print q
 +
            raise TypeError, "non-string non-list!!!"
 +
    return stringish
  
  def replacer(stringie, old, new):
+
def TSVinput(filename):
      """
+
    """tab separated database parser
      """
+
    """
      name2=""
+
    # Open filename
      for q in stringie:
+
    tsv=open(filename)
          if q == old: name2 += new
+
    # Convert to list
          else: name2 += q
+
    ## get list of lines
      return name2
+
    biglist = tsv.readlines()
 +
    #for q in tsv:
 +
    #    biglist += q
 +
    tsv.close()
 +
    ## parse lines
 +
    #for q in biglist: print q
 +
    newlist = []
 +
    for q in biglist:
 +
        newlist += [q.split("\t")]
 +
        # print max(max(newlist))
 +
    # return list
 +
    return newlist
  
  def refbreak(ref):
+
def StartXML():
      """
+
    out  = [['<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.3/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/ http://www.mediawiki.org/xml/export-0.3.xsd" version="0.3" xml:lang="en">\n']]
      """
+
    out +=  ['    <siteinfo>\n']
      return replacer(ref,";",";<<B></B>BR/>")
+
    out +=  ['        <sitename>Lunarpedia</sitename>\n']
 +
    out +=  ['    </siteinfo>\n']
 +
    return out
  
 +
def EndXML():
 +
    out  = [['</mediawiki>\n']]
 +
    return out
  
  ##def ():
+
def ArtXML(title, contrib, text):
   ##   """
+
    '''XML markup for article in file
  ##    """
+
    title --   title of article
  ##    return "() not implemented"
+
    contrib -- name of script (ie Autostub2)
  ##
+
    text --    the article
  ##def ():
+
    '''
  ##    """
+
    out  = [['   <page>\n']]
  ##   """
+
    out +=  ['        <title>'+title+'</title>\n']
   ##    return "() not implemented"
+
    out +=  ['        <revision>\n']
 +
    out +=  ['            <contributor>\n']
 +
    out +=  ['                <username>'+contrib+'</username>\n']
 +
    out +=  ['            </contributor>\n']
 +
    # out +=  ['            <text xml:space="preserve">'+text+'</text>']
 +
    out +=  ['            <text xml:space="preserve">']
 +
    out +=  text
 +
    out +=  ['</text>\n']
 +
    out +=  ['        </revision>\n']
 +
    out +=  ['   </page>\n']
 +
    
  
  
  #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 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."]
+
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)
+
What=dofeature(Item)
  for q in What: print q
+
for q in What: print q
 +
</PRE>

Latest revision as of 07:46, 10 July 2007

Erratum

  • Category tag for 'Location' should have been 'Locations'

-- Strangelv 18:27, 4 November 2006 (PST)


Problems

  • How to tie the satellite crater articles to the main crater articles when the USGS database doesn't link them?
  • What is the area of each sector in km**2?
  • How might the script determine if a given feature is in a given sector? If we treat each item as a perfect circle, how do we determine which sectors include portions of that circle?
  • Can we automatically do maps for features near the poles?

-- Strangelv 18:13, 4 November 2006 (PST)


To Do

  • Sector areas ---- I posted the solution to this Charles F. Radley 17:53, 16 January 2007 (PST)
  • Match sectors and features (not just centers) -- easy to solve, will do on a weekend or snow day Charles F. Radley 17:53, 16 January 2007 (PST)
  • Match satellite craters with their central craters - Where is the list of satellite craters? Charles F. Radley 17:53, 16 January 2007 (PST)
I have the data downloaded, but I can't find the URL from the USGS page I got it from. -- Strangelv 18:38, 16 January 2007 (PST)
  • Border case handling for when feature center is on the boundary of two or four sectors - What do you want it to do in those cases ? Charles F. Radley 17:53, 16 January 2007 (PST)
Possibly list as included in all of the above? -- Strangelv 18:38, 16 January 2007 (PST)
  • Automatically load and parse tab delimited CSV --- Is this done now ? Charles F. Radley 17:53, 16 January 2007 (PST)
No. You may notice the hard-coded data entry in the script. 8) I basically cranked out the essentials to produce the test page and then got sidetracked as well as stopped by a few technical issues listed on this page. -- Strangelv 18:38, 16 January 2007 (PST)
  • Automatically output articles in XML for bulk import
  • Automatically generate map files for suitably large features
  • Automatically generate sector articles and maps

-- Strangelv 18:13, 4 November 2006 (PST)

Bonus Points

  • Is there a public domain database of rille?
  • Are there other public domain databases of use that we might be able to merge into this to add details to sectors and features (such as surface samples)?

-- Strangelv 18:13, 4 November 2006 (PST)

The precise coordinates of the Apollo sites are available on the web link provided on that page. Charles F. Radley 17:50, 16 January 2007 (PST)

Just need to add those to the database if they're not already there. I believe several features named on the ground are already in there. -- Strangelv 18:38, 16 January 2007 (PST)
  • Is there a public domain database that represents non-circular features in a non-circular manner?

-- Strangelv 16:25, 27 December 2006 (PST)

How about approximating them to ellipses? Standard geometry equations. Charles F. Radley 17:49, 16 January 2007 (PST)

Sounds great if it can be found. I've only seen one database though, and it treats everything as circles whether perfectly appropriate or wildly inappropriate. Manually changing them ourselves at this stage isn't feasible given the sheer number of features in the database. -- Strangelv 18:38, 16 January 2007 (PST)

Software Development Plan

Moved to Lunarpedia_talk:Autostub1#Software_Development_Plan


Source Code

Warning: Put in place with <PRE> tags, which change some formatting. Copy from the edit or view source page to get an accurate copy.

And yes, the code is really rough in a few places (like where reinventing the wheel is faster than remembering where the wheel is). The language is Python. 2.4 and later should work; earlier may require replacing my '//' division with integer coercion.

#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#
#                             #
# Autostub 1                  #
#                             #
# Feature Autostub Generator  #
#                             #
# Public Domain               #
#                             #
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#

def dofeature(thisentry):
    """Generates article on a feature given in thisentry
      
                 00 -- system (will always be 'Earth'
                 01 -- satellite (will always be Moon)  
    name         02 -- name
    lat          03 -- USGS latitude
                 04 -- USGS longitude
    me_long = poslong(thisentry[4])   -- Mean Earth longitude
    mo_long = me2mo(me_long)          -- Mare Orientale longitude
    me_coord = coordstr(me_long, lat) -- string for Mean Earth coordinates
    mo_coord = coordstr(mo_long, lat) -- string for Mare Orientale coordinates
                 05 -- starting latitude (never provided, unfortunately)
                 06 -- ending latitude (never provided, unfortunately)
                 07 -- starting longitude (never provided, unfortunately)
                 08 -- ending longitude (never provided, unfortunately)    
                 09 -- DIR (???)
    dia          10 -- diameter in klicks
                 11 -- CT (country of discovery?)
                 12 -- Continent (of discovery?)
                 13 -- ET (???)
                 14 -- Ethnicity (of name?)
                 15 -- Quad (USGS map info)
                 16 -- Map (USGS map info)
                 17 -- AS (???)
    approvalStat 18 -- Approved Status Description
    approvalYear 19 -- Approval Date (year)
                 20 -- REF (???)
    reference    21 -- References
                 22 -- FT (Feature Type categorization, presumably)
    featuretype  23 -- Feature Type Name
    origin       24 -- origin
    
    
    """

    #   
    # 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 equatorial"

    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"


def Stringify(listish):
    stringish = "" 
    for q in listish:
        if type(q) == type('str'):
           stringish += q
           #print "str"
        elif type(q) == type([]):
           stringish += Stringify(q)
           #print "list"
        else: 
             print type(q)
             print q
             raise TypeError, "non-string non-list!!!"
    return stringish 

def TSVinput(filename):
    """tab separated database parser
    """
    # Open filename
    tsv=open(filename)
    # Convert to list
    ## get list of lines
    biglist = tsv.readlines()
    #for q in tsv:
    #    biglist += q
    tsv.close()
    ## parse lines
    #for q in biglist: print q
    newlist = []
    for q in biglist:
        newlist += [q.split("\t")]
        # print max(max(newlist))
    # return list
    return newlist

def StartXML():
    out  = [['<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.3/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/ http://www.mediawiki.org/xml/export-0.3.xsd" version="0.3" xml:lang="en">\n']]
    out +=  ['    <siteinfo>\n']
    out +=  ['        <sitename>Lunarpedia</sitename>\n']
    out +=  ['    </siteinfo>\n']
    return out

def EndXML():
    out  = [['</mediawiki>\n']]
    return out

def ArtXML(title, contrib, text):
    '''XML markup for article in file
    title --   title of article
    contrib -- name of script (ie Autostub2)
    text --    the article
    '''
    out  = [['    <page>\n']]
    out +=  ['        <title>'+title+'</title>\n']
    out +=  ['        <revision>\n']
    out +=  ['            <contributor>\n']
    out +=  ['                <username>'+contrib+'</username>\n']
    out +=  ['            </contributor>\n']
    # out +=  ['            <text xml:space="preserve">'+text+'</text>']
    out +=  ['            <text xml:space="preserve">']
    out +=  text
    out +=  ['</text>\n']
    out +=  ['        </revision>\n']
    out +=  ['    </page>\n']
  


#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=dofeature(Item)
for q in What: print q