The HogModel calculates a temperature for every simulated hour, basing the value on the latitude and the hour of day and the day of year.  Interfaces to the model have tradiitonally hidden the actual coordinates while exposing a selection of Southeastern States for users.  Information for State Name, State Abbreviation, Average Latitude, & Average Longitude was collected for two sets, the original HogModel Thirteen and a set including All 50 States.  Both sets of xml data adhere to the StatesData schema shown here.

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="StatesData" targetNamespace="http://spb.xanderlih.com/Schemas/StatesData" xmlns:mstns="http://spb.xanderlih.com/Schemas/StatesData" xmlns="http://spb.xanderlih.com/Schemas/StatesData" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified">
  <xs:annotation>
    <xs:appinfo source="urn:schemas-microsoft-com:xml-msdatasource">
      <DataSource DefaultConnectionIndex="0" FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout, AnsiClass, Class, Public" SchemaSerializationMode="IncludeSchema" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
        <Connections />
        <Tables />
        <Sources />
      </DataSource>
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="StatesData" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msprop:Generator_UserDSName="StatesData" msprop:Generator_DataSetName="StatesData">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="State" msprop:Generator_UserTableName="State" msprop:Generator_RowDeletedName="StateRowDeleted" msprop:Generator_RowChangedName="StateRowChanged" msprop:Generator_RowClassName="StateRow" msprop:Generator_RowChangingName="StateRowChanging" msprop:Generator_RowEvArgName="StateRowChangeEvent" msprop:Generator_RowEvHandlerName="StateRowChangeEventHandler" msprop:Generator_TableClassName="StateDataTable" msprop:Generator_TableVarName="tableState" msprop:Generator_RowDeletingName="StateRowDeleting" msprop:Generator_TablePropName="State" maxOccurs="79228162514264337593543950335">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Name" msprop:Generator_UserColumnName="Name" msprop:Generator_ColumnPropNameInRow="Name" msprop:Generator_ColumnVarNameInTable="columnName" msprop:Generator_ColumnPropNameInTable="NameColumn" type="xs:string" />
              <xs:element name="Abbreviation" msprop:Generator_UserColumnName="Abbreviation" msprop:Generator_ColumnPropNameInRow="Abbreviation" msprop:Generator_ColumnVarNameInTable="columnAbbreviation" msprop:Generator_ColumnPropNameInTable="AbbreviationColumn" type="xs:string" default="" />
              <xs:element name="AvgLatitude" msprop:Generator_UserColumnName="AvgLatitude" msprop:Generator_ColumnPropNameInRow="AvgLatitude" msprop:Generator_ColumnVarNameInTable="columnAvgLatitude" msprop:Generator_ColumnPropNameInTable="AvgLatitudeColumn" type="xs:double" />
              <xs:element name="AvgLongitude" msprop:Generator_UserColumnName="AvgLongitude" msprop:Generator_ColumnPropNameInRow="AvgLongitude" msprop:Generator_ColumnVarNameInTable="columnAvgLongitude" msprop:Generator_ColumnPropNameInTable="AvgLongitudeColumn" type="xs:double" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
    <xs:unique name="Constraint1" msdata:PrimaryKey="true">
      <xs:selector xpath=".//mstns:State" />
      <xs:field xpath="mstns:Abbreviation" />
    </xs:unique>
  </xs:element>
</xs:schema>

StatesData_SchemaDiagram.png

 

I didn't write the StatesData schema, I drew it using the Visual Studio DataSet Designer.

But, drawing out the dataset made writing the StateInfo class much easier.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
namespace SharpSpb.Schema
{
    /// <summary>
    /// Information on Abbreviation, Name, Average Latitude, and Average Longitude
    /// for the United States
    /// </summary>
    public sealed class StateInfo : DependencyObject
    {
        /// <summary>
        /// StateInfo objects for the valid Southern States
        /// </summary>
        public static List<StateInfo> SouthernStates { get; private set; }
        /// <summary>
        /// StateInfo objects for the United States 
        /// </summary>
        public static List<StateInfo> UnitedStates { get; private set; }
        /// <summary>
        /// Set up static StateInfo List properties
        /// </summary>
        static StateInfo()
        {
            SouthernStates = (from SharpSpb.Schema.StatesData.StateRow zSt in ResourceUtility.GetStoredStatesData(true).State
                              select new StateInfo(zSt)).ToList();
            UnitedStates = (from SharpSpb.Schema.StatesData.StateRow zSt in ResourceUtility.GetStoredStatesData(false).State
                            select new StateInfo(zSt)).ToList();
        }
        #region State Properties
        /// <summary>
        /// 
        /// </summary>
        public String StateAbbreviation
        {
            get { return (String)GetValue(StateAbbreviationProperty); }
            set { SetValue(StateAbbreviationProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        public static readonly DependencyProperty StateAbbreviationProperty =
            DependencyProperty.Register("StateAbbreviation", typeof(String), typeof(StateInfo), new PropertyMetadata("AL"));
        /// <summary>
        /// 
        /// </summary>
        public String StateName
        {
            get { return (String)GetValue(StateNameProperty); }
            set { SetValue(StateNameProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        public static readonly DependencyProperty StateNameProperty =
            DependencyProperty.Register("StateName", typeof(String), typeof(StateInfo), new PropertyMetadata("Alabama"));
        /// <summary>
        /// Average Value
        /// </summary>
        public Double Latitude
        {
            get { return (Double)GetValue(LatitudeProperty); }
            set { SetValue(LatitudeProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        public static readonly DependencyProperty LatitudeProperty =
            DependencyProperty.Register("Latitude", typeof(Double), typeof(StateInfo), new PropertyMetadata(32.7));
        /// <summary>
        /// Average Value
        /// </summary>
        public Double Longitude
        {
            get { return (Double)GetValue(LongitudeProperty); }
            set { SetValue(LongitudeProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        public static readonly DependencyProperty LongitudeProperty =
            DependencyProperty.Register("Longitude", typeof(Double), typeof(StateInfo), new PropertyMetadata(-86.5));
        #endregion
        #region Constructors
        /// <summary>
        /// Default constructor creates a StateInfo object for Alabama-SPB
        /// </summary>
        public StateInfo()
        {
        }
        /// <summary>
        /// Specify state by row fom dataset
        /// </summary>
        /// <param name="pStateRow"></param>
        public StateInfo(StatesData.StateRow pStateRow)
        {
            CreateStateFromDataRow(pStateRow);
        }
        /// <summary>
        /// Get a StateInfo for a state specified by Abbreviation or Name.
        /// Optionally get values from the Full-50 State Latitude and Longitude
        /// by opting-out of the default valuse from the SPB Southern 12.
        /// StateInfo for states not in the Southern 12, the only available
        /// coordinates are from the Full-50 set.
        /// </summary>
        /// <param name="pStateNameOrAbbreviation"></param>
        /// <param name="pUseOriginalSpbValues"></param>
        public StateInfo(String pStateNameOrAbbreviation, Boolean pUseOriginalSpbValues)
        {
            if (pStateNameOrAbbreviation.Length == 2)
            { CreateStateFromAbbreviation(pStateNameOrAbbreviation, pUseOriginalSpbValues); }
            else
            { CreateStateFromName(pStateNameOrAbbreviation, pUseOriginalSpbValues); }
        }
        /// <summary>
        /// Get StateInfo from name or abbreviation, Southern States get
        /// coordinates from original SPB Model Southern 12 set. Other
        /// states get values from SharpSpb set of all 50 states.
        /// </summary>
        /// <param name="pStateNameOrAbbreviation"></param>
        public StateInfo(String pStateNameOrAbbreviation)
        {
            if (pStateNameOrAbbreviation.Length == 2)
            { CreateStateFromAbbreviation(pStateNameOrAbbreviation); }
            else
            { CreateStateFromName(pStateNameOrAbbreviation); }
        }
        #endregion
        #region Private Create Methods
        void CreateStateFromName(string pStateNameOrAbbreviation, bool pUseOriginalSpbValues)
        {
            StatesData qStates = ResourceUtility.GetStoredStatesData(pUseOriginalSpbValues);
            if (!qStates.State.Any(st => st.Name == pStateNameOrAbbreviation))
            { CreateNonSouthernState(pStateNameOrAbbreviation); }
            else
            { CreateStateFromDataRow(qStates.State.Single(st => st.Name == pStateNameOrAbbreviation)); }
        }
        void CreateStateFromAbbreviation(string pStateNameOrAbbreviation, bool pUseOriginalSpbValues)
        {
            StatesData qStates = ResourceUtility.GetStoredStatesData(pUseOriginalSpbValues);
            if (qStates.State.FindByAbbreviation(pStateNameOrAbbreviation) != null)
            { CreateStateFromDataRow(qStates.State.FindByAbbreviation(pStateNameOrAbbreviation)); }
            else
            { CreateNonSouthernState(pStateNameOrAbbreviation); }
        }
        void CreateStateFromName(string pStateNameOrAbbreviation)
        {
            CreateStateFromName(pStateNameOrAbbreviation, true);
        }
        void CreateStateFromAbbreviation(string pStateNameOrAbbreviation)
        {
            CreateStateFromAbbreviation(pStateNameOrAbbreviation, true);
        }
        void CreateNonSouthernState(string pStateNameOrAbbreviation)
        {
            StatesData qStates = ResourceUtility.GetStoredStatesData(false);
            if (!qStates.State.Any(st => st.Name == pStateNameOrAbbreviation || st.Abbreviation == pStateNameOrAbbreviation))
            {
                this.StateName = "Not Found: " + pStateNameOrAbbreviation;
                this.StateAbbreviation = "XX";
            }
            if (pStateNameOrAbbreviation.Length == 2)
            {
                CreateStateFromDataRow(qStates.State.FindByAbbreviation(pStateNameOrAbbreviation));
            }
            else
            {
                CreateStateFromDataRow(qStates.State.Single(st => st.Name == pStateNameOrAbbreviation));
            }
        }
        void CreateStateFromDataRow(StatesData.StateRow pStateRow)
        {
            StateName = pStateRow.Name;
            StateAbbreviation = pStateRow.Abbreviation;
            Latitude = pStateRow.AvgLatitude;
            Longitude = pStateRow.AvgLongitude;
        }
        #endregion
    }
}

 

 

Check XHTML « spb.xanderlih.com Copyright © Xander Lih 2000-2012  » Check CSS