بسم الله الرحمن الرحيم
أنا طالب سنة أولى في جامعة ساوثهامتون البريطانية (أحد الجامعات الرائدة في مجال الإلكترونيات وعلوم الحاسب).
الزبدة أنا مطالب بكورس ورك يمثل 50% من درجة مادة برمجة. الكورس ورك ينص على محاكاة Iphone application إسمه UK Grid Carbon intensity
وهذه صورة البرنامج:

على أن أطور برنامج شبيه لعملية هذا البرنامج ولكن بشكل مناسب لتطبيقات الـPC
عموما الحمدلله إستطعت ربط البرنامج بملف الـXML الذي يقوم بإستخراج البيانات كل 5 دقائق. كما هو موضح في الصورة :

المشكلة:
الآن لحساب الكثافة الكربونية علي أن اطبق العملية الرياضية التالية (إسمحوا لي أكتبها بالإنجليزي لأني تعبت من ترجمة الأفكار للعربي)
To calculate the grid carbon intensity we multiply each fuel type percentage by the conversion factor and then divide by 100, then we multiply this number by 1.09 to reflect the transmission losses
The conversion factor of each fuel type is fixed as addressed in the following table
Fuel type - Conversion factor
Gas - 360
Coal - 910
Nuclear - 16
Wind - 0
Hydro - 0
كيف يمكني أن أقوم بهذه العملية الحسابية وتخزين الناتج في CarbonIntensity
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;
using System.Net;
using System.Xml;
namespace GridCarbon
{
class Model
{
//Carbon Intensity Variable
private int carbonIntensity;
//Percentage variables
private string gasP;
private string coalP;
private string nuclearP;
private string windP;
private string hydroP;
//MW variables
private string gasValue;
private string coalValue;
private string nuclearValue;
private string windValue;
private string hydroValue;
//Properties
//Carbon Intensity property
public int CarbonIntensity
{
set { carbonIntensity = value; }
get { return carbonIntensity; }
}
//Gas property
public string GasValue
{
set { gasValue = value; }
get { return gasValue; }
}
//Coal property
public string CoalValue
{
set { coalValue = value; }
get { return coalValue; }
}
//Nuclear property
public string NuclearValue
{
set { nuclearValue = value; }
get { return nuclearValue; }
}
//Wind property
public string WindValue
{
set { windValue = value; }
get { return windValue; }
}
//Hydro property
public string HydroValue
{
set { hydroValue = value; }
get { return hydroValue; }
}
//Gas percentage property
public string GasP
{
set { gasP = value; }
get { return gasP; }
}
//Coal percentage property
public string CoalP
{
set { coalP = value; }
get { return coalP; }
}
//Nuclear percentage property
public string NuclearP
{
set { nuclearP = value; }
get { return nuclearP; }
}
//Wind percentage property
public string WindP
{
set { windP = value; }
get { return windP; }
}
//Hydro percentage property
public string HydroP
{
set { hydroP = value; }
get { return hydroP; }
}
//Constructor
public Model()
{
}
//XML fetcher
private Stream GetXML()
{
string url = "http://www.bmreports.com/bsp/additional/soapfunctions.php?element=generationbyfueltypetable";
Stream retStream = new WebClient().OpenRead(url);
return retStream;
}
//XML reader
bool reading = false;
public void UpdateData()
{
XmlTextReader xmlReader = new XmlTextReader(GetXML());
while (xmlReader.Read())
{
if (xmlReader.NodeType == XmlNodeType.Element)
{
//Reading latest update only (INST attribute only)
if (xmlReader.Name.Equals("INST"))
{
reading = true;
}
//Assigning values for the MW/Percentage variables
if ((xmlReader.Name.Equals("FUEL")) && reading)
{
string type = xmlReader.GetAttribute(0);
//Assigning Gas
if (type.Equals("CCGT"))
{
gasValue = xmlReader.GetAttribute(2);
gasP = xmlReader.GetAttribute(3);
}
//Assigning Coal
if (type.Equals("COAL"))
{
coalValue = xmlReader.GetAttribute(2);
coalP = xmlReader.GetAttribute(3);
}
//Assigning Nuclear
if (type.Equals("NUCLEAR"))
{
nuclearValue = xmlReader.GetAttribute(2);
nuclearP = xmlReader.GetAttribute(3);
}
//Assigning Wind
if (type.Equals("WIND"))
{
windValue = xmlReader.GetAttribute(2);
windP = xmlReader.GetAttribute(3);
}
//Assigning Hydro
if (type.Equals("NPSHYD"))
{
hydroValue = xmlReader.GetAttribute(2);
hydroP = xmlReader.GetAttribute(3);
}
}
}
//End of Reading the latest update (INST attribute)
else if (xmlReader.NodeType == XmlNodeType.EndElement)
{
if (xmlReader.Name.Equals("INST"))
{
reading = false;
}
}
}
}
public void WriteXML(TextWriter tw)
{
tw.WriteLine("<Gas>");
tw.WriteLine("<GasValue>" + gasValue + "</GasValue>");
tw.WriteLine("<GasPercentage>" + gasP + "</GasPercentage>");
tw.WriteLine("</Gas>");
tw.WriteLine ("<Coal>");
tw.WriteLine("<CoalValue>" + coalValue + "</Coalvalue>");
tw.WriteLine("<CoalPercentage>" + coalP + "</CoalPercentage>");
tw.WriteLine("</Coal>");
}
//Writing XML
public void WriteXML()
{
TextWriter tw = new StreamWriter("model.xml");
tw.WriteLine ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
WriteXML(tw);
tw.Close();
}
public void ReadXML()
{
XmlTextReader xmlReading = new XmlTextReader("model.xml");
string text = "";
}
}
}
using System;
الملفات مضغوطة في المرفقات
شاكرا لكم جهودكم ومقدر
مع أطيب تحياتي