0

I am a bit confused with my own work, i seemed to have complicated my issue.

I am pulling data off a call dialer, this dialer logs all the calls for all the agents and each agent is in a queue, there can be multiple agents in the same queue.

My basic calculations in SQL i can pull the date, queue, hours and number of calls per each hour that looks as follows:

callDate    queueid    cHour    numberOfCalls
2013-05-03  No Queue     0            1
2013-05-03  No Queue     2            1
2013-05-03  No Queue     6            1
2013-05-03  No Queue     7            7
2013-05-03  No Queue     8            6
2013-05-03  No Queue     9            14
2013-05-03  No Queue     10           6
2013-05-03  No Queue     11           5
2013-05-03  No Queue     12           8
2013-05-03  17001        7            114
2013-05-03  17001        8            238
2013-05-03  17001        9            227
2013-05-03  17001        10           190
2013-05-03  17001        11           221
2013-05-03  17001        12           73
2013-05-03  17002        6            3
2013-05-03  17002        7            125 

There you can see the Queue, The hour and how many calls for that hour (hour being 7am, 8am... etc).

i need to know if i create a multidimensional array to stor the queue, the hour and number of calls for each queue, for each hour (if that makes sense?) so that i can later use that as a graph?

Here is my sample code that i have gotten stuck up to:

Xaml:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:DV="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    xmlns:DVC="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    xmlns:ThemeManager.ThemeName="MetropolisDark"
    Title="MainWindow" Height="350" Width="525">
<Grid>

    <DVC:Chart Name="Chart"
               Background="#463F3F">                
        <DVC:Chart.PlotAreaStyle>
            <Style TargetType="Grid">
                <Setter Property="Background" Value="Transparent" />
            </Style>
        </DVC:Chart.PlotAreaStyle>
    </DVC:Chart>

</Grid>

C#:

    private void AllAgentHourData()
    {
        string[] queueid = new string[100];
        int[] callHour = new int[100];
        int count = 0;
        int counter = 0;

        SqlConnection sqlConnection1 = new SqlConnection("Server=nl-reportserver;Database=RC_Dailer_WH;User Id=sa;Password=d@[email protected]");
        SqlCommand cmd = new SqlCommand();
        SqlDataReader reader;

        //cmd.CommandText = "SELECT * FROM RC_call_logs WHERE convert(date,call_logdate,120) = convert(date,GETDATE(),120)";
        cmd.CommandText = "Select distinct queueid from RC_call_logs order by queueid";
        cmd.CommandType = CommandType.Text;
        cmd.Connection = sqlConnection1;

        sqlConnection1.Open();

        reader = cmd.ExecuteReader();
        if (reader.HasRows)
        {
            while (reader.Read())
            {
                queueid[count] = reader.GetString(0);
            }
        }
        else
        {
            MessageBox.Show("No Error message");
        }
        reader.Close();

        sqlConnection1.Close();

        Random random = new Random();

        //Chart is your chart object in Xaml
        //declare your series
        for (int i = 1; i < 10; i++)
        {
            LineSeries ls = new LineSeries();

            ls.Title = i.ToString();
            ls.IndependentValueBinding = new Binding("Key");
            ls.DependentValueBinding = new Binding("Value");

            ls.ItemsSource = new KeyValuePair<DateTime, int>[]{
            new KeyValuePair<DateTime,int>(DateTime.Now             , random.Next(1000)),
            new KeyValuePair<DateTime,int>(DateTime.Now.AddMonths(1), random.Next(10, 1000)),
            new KeyValuePair<DateTime,int>(DateTime.Now.AddMonths(2), random.Next(10, 1000)),
            new KeyValuePair<DateTime,int>(DateTime.Now.AddMonths(3), random.Next(10, 1000)),
            new KeyValuePair<DateTime,int>(DateTime.Now.AddMonths(4), random.Next(10, 1000))};

            // then add it to the chart
            Chart.Series.Add(ls);
        }

    }
7
  • Please read meta.stackexchange.com/questions/10647/… Commented May 3, 2013 at 12:22
  • thanks but i do not know how else to word this hence the long question Commented May 3, 2013 at 12:25
  • 2
    dont use a multidimensional array for anything. Commented May 3, 2013 at 12:30
  • haha it looks horrid to use Commented May 3, 2013 at 12:33
  • @Silentdarkness, no really, if you want an array with multiple bounds use a jagged array. Commented May 3, 2013 at 12:49

2 Answers 2

1

I'm not really sure what you're trying to achieve but something like this may help.

Dictionary<DateTime, Dictionary<string, KeyValuePair<int,int>>> dicData

DateTime being your DateTime, string being your Queue and int,int in KeyValuePair is hour and numberOfCall pair.

Edit 1:

Actually it has to be List of KeyValuePair. And here is an example:

Dictionary<DateTime, Dictionary<string, List<KeyValuePair<int, int>>>> dicData = new Dictionary<DateTime, Dictionary<string, List<KeyValuePair<int, int>>>>();
        //dt is your result from SQL query
        foreach (DataRow dr in dt.Rows)
        {
            DateTime dtm = DateTime.Parse(dr["DateTime"].ToString());
            string queue = dr["Queue"].ToString();
            int hours = int.Parse(dr["Hours"].ToString());
            int cycles = int.Parse(dr["Cycles"].ToString());

            //Adding Distinct DateTime objects as Key
            if(!dicData.ContainsKey(dtm))
            {
                dicData[dtm] = new Dictionary<string, KeyValuePair<int, int>>();
            }

            //Adding distinct Queue object as Key under the DateTime dictionary
            if (!dicData.ContainsKey(queue))
            {
                dicData[dtm][queue] = new List<KeyValuePair<int, int>>();
            }
            dicData[dtm][queue].Add(new KeyValuePair<int, int>(hours, cycles));
        }
Sign up to request clarification or add additional context in comments.

2 Comments

this will work, can you supply me with a practical example other than the answer to help me with this? it will be the first time i have used this but makes sence.
DataTable dt = new DataTable(); You can fill it with an SqlDataAdapter lets say "da" by: da.Fill(dt);
0

EDIT

so, in your reading while loop you could do,

while (reader.Read())
{
    var callHour = new CallHour(
        DateTime.ParseExact("yyyy-mm-dd", reader.GetString(0)),
        reader.GetInt32(2),
        reader.GetInt32(3),
        reader.IsDBNull(1) ? null : reader.GetInt32(1));

    callHours.Add(callHour.Time, callHour);
}

Make a class, your could call it CallHour then you can have some generic collection of CallHour. That generic collection would support IEnumerable<CallHour> and possibly IList<CallHour>.


public class CallHour
{
     private readonly DateTime time;

     public CallHour(
            DateTime day,
            int hour,
            int callCount,
            int? queueId = null)
     {
         this.hour = new DateTime(
             day.Year,
             day.Month,
             day.Day,
             hour,
             0,
             0,
             0);

         this.CallCount = callCount;
         this.QueueId = queueId;
     }

     public DateTime Time
     {
         get
         {
             return this.time;
         }
     }

     public int? QueueId { get; set; }
     public int CallCount { get; set; }
}    

Then you could declare a sorted list, and add your first hour.

var callHours = new SortedList<DateTime, CallHour>();

var someCallHour = new CallHour(
    DateTime.Parse("2013-05-03 00:00:00"), 0, 1);

callHours.Add(someCallHour.Time, someCallHour);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.