الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

صياغة العمليات الرياضية لحساب الكثافة الكربونية

بدأه Abdullah Almaatouq في 10 مايو 2010 · 4 رد · 626 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بسم الله الرحمن الرحيم

أنا طالب سنة أولى في جامعة ساوثهامتون البريطانية (أحد الجامعات الرائدة في مجال الإلكترونيات وعلوم الحاسب).

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

وهذه صورة البرنامج:

100107083902.jpg

على أن أطور برنامج شبيه لعملية هذا البرنامج ولكن بشكل مناسب لتطبيقات الـPC

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

131297530.jpg

المشكلة:

الآن لحساب الكثافة الكربونية علي أن اطبق العملية الرياضية التالية (إسمحوا لي أكتبها بالإنجليزي لأني تعبت من ترجمة الأفكار للعربي)

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;

الملفات مضغوطة في المرفقات

شاكرا لكم جهودكم ومقدر

مع أطيب تحياتي

GridCarbon_2.zip

تم تعديل هذه المشاركة بواسطة Abdullah Almaatouq في 10 مايو 2010 في 19:52

#2

أخى على حسب فهمى ممكن تكون دالة الحساب بهذا الشكل

 public double ComputeIntensity(double percent, double Factor)
    {              
        double result;
        double a = (percent*Factor)/100;
        double b = a*1.09;
        result = b ;

        return result;
    }

تم تعديل هذه المشاركة بواسطة عمرو الصعيدي في 10 مايو 2010 في 21:07

1

 وممّا زادنـــي شرفــاً وتيهــاً   **  وكدت بأخمصي أطأ الثريّا

دخولي تحت قولك يا عبادي  **   وأن صيّرت أحمد لي نبيّـاً

#3

شكرا جزيلا على مساعدتك يا أخي ..

لأوضح لك أكثر .. ستكون العملية الرياضية كاملة كالآتي :

Carbon Intensity = Gas Percentage * Gas factor + Coal Percentage * Coal Factor + Nuclear Percentage * Nuclear Factor +Wind Percentage * Wind factor + Hydro percentage * Hydero factor

Then devided by 100

then multiplyed by 1.09

مع العلم إنه النسبة جايبها من الـXML من مصدر أونلاين

  	//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);



  }





  	}



  	}

أخوي جرب تحمل الملف المرفق .. بيكون فيه خطأ في الform.cs لأنه بيحاول يفتحها من different path

الله لا يهينك إذا ممكن تعدل البرنامج من ناحية العملية الرياضية .. وتشوف لي ليش بعد ما أسكر البرنامج وأفتحه مرة ثانية .. ما يقرأ آخر معلومات مخزنة

 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 = "";

  	}

after the application is closed, it should write an XML file and next time its opened the application should read from it. thus the last results will appear.

مع أطيب تحياتي أخوي ..

تم تعديل هذه المشاركة بواسطة Abdullah Almaatouq في 11 مايو 2010 في 02:02

#4

Dear all

sorry i'll have to t ype in English as i am submitting the thread from the University labs.

I have added the following function

 	//calculations
 	public double Calculation(double gasP, double coalP, double nuclearP, double windP, double hydrop, double gasF, double coalF, double nuclearF, double windF, double hydroP, double hydroF)
 	{
 	double CarbonIntensity;
 	double a = (gasP * gasF) + (coalP * coalF) + (nuclearP * nuclearF) + (windP * windF) + (hydroP * hydroF) / 100;
 	CarbonIntensity = a * 1.09;
 	return CarbonIntensity;
 	}

and had one error

the first one is when i call the methode

No overload for method 'Calculation' takes '0' arguments

please find in the attachments the correct source files.

thanks alot

Project INFO1007.zip

تم تعديل هذه المشاركة بواسطة Abdullah Almaatouq في 11 مايو 2010 في 17:13

#5

well thanks alot :) i have done some progress tho ..

I managed to make it work and show the final answer, now still i need two more things to finish the project

1- If else statement that changes the map colour to red/green/ yellow depending on the value of the carbon intensity

<500 RED

>250 GREEN

between them it is yellow

2- I need an exception shows an error message when there is no internet connection

you can download the source file from

http://users.ecs.soton.ac.uk/aa1e09/info1007.zip

thanks

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…