ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 22nd, 2005, 10:48 AM
midimidi midimidi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 83 midimidi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 29 m
Reputation Power: 4
Some logic help needed.

Hello all - I'm really stumped on this, and just can't find a way to do it.

I am working on a TV schedule (still). The data coming is very messy, so its taken a while to sort it correctly.

I currently have it coming in as a two dimensional Array with a Structure. Dimension one is Time (going down the far-left column) dimension two is up to 7 entries (for days of the week at the top).

TimeArray[1][1].ID, .Series, .Episode, .Time, .Date, .Rowspan, etc

The table is then looped through writing out by rows (a limitation of HTML). Note that the second dimension can have anywhere from 1-7 items. I've added rowspan to signify a 30 minute program as 1 row, 1 hour is 2 rows, etc.

Generally, the schedule fills up correctly. i.e. if row1 has 7 items and two of them are rowspan=2 (1 hour programs), then row2 *generally* has only 5 items, and they flush out to their correct days.

Here's the problem. When you get to the bottom of the schedule, you might have only one program, say on Thursday. Rather than appear on Thursday, it appears on Monday.

My first try was a secondary loop before outputting, from 1-7, where if the Date was wrong, it would display an empty cell, and if it was right, it cfbreak and output. This doesn't work, because for the row2 explained above, where there are only 5 items, it would display empty cells where the 1 hour programs from row1 would span downwards.

Here's some sample code. Any help on this problem is much appreciated, but I'm starting to wonder if this is even possible at all.

Code:
<cfloop index="a" from="1" to="#ArrayLen(TimeArray)#"> <!--- Generally = 35 for 9:00am to 2:30am the day after, in 30 minute increments --->
  <tr valign="top">
  <td width="10%">#TimeFormat(TimeArray[a][1].Time, 'h:mm tt')#</td> <!--- write to 30-min time column --->

  <cfset display_date = first day of the week> <!--- reset back to Monday --->
  <cfloop index="b" from="1" to="#ArrayLen(TimeArray[a])#"> <!--- loop through data for one 30-min set --->
    <cfloop index="c" from="1" to="7"> <!--- check Date --->
      <cfif #TimeArray[a].Date# eq #display_date#>
        <cfset display_date = DateFormat(DateAdd("d", 1, display_date),"mm/dd/yyyy")> <!--- increment one day, goto output --->
        <cfbreak>
      <cfelse>
        <td>nothing!</td>
        <cfset display_date = DateFormat(DateAdd("d", 1, display_date),"mm/dd/yyyy")> <!--- increment one day, the date is wrong --->
      </cfif>
    </cfloop>

  <!---write out current element in a cell --->
  <td width="12%" rowspan="#TimeArray[a].Rowspan#">#TimeArray[a].Series#
  </cfloop>
  </tr> <!--- move to next 30 minute row --->
</cfloop>

Reply With Quote
  #2  
Old March 22nd, 2005, 10:56 AM
bocmaxima's Avatar
bocmaxima bocmaxima is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2004
Location: Tucson, Sonora
Posts: 1,322 bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 17 h 44 m 38 sec
Reputation Power: 22
Send a message via AIM to bocmaxima
To get an idea of your app, can you post your current HTML output as well?

Reply With Quote
  #3  
Old March 22nd, 2005, 01:34 PM
midimidi midimidi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 83 midimidi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 29 m
Reputation Power: 4
Quote:
Originally Posted by bocmaxima
To get an idea of your app, can you post your current HTML output as well?


Gladly - the following table illustrates just about everything mentioned. Again, note how the first two rows line up nicely (which is quite typical through most of what I've looked at it), but the last two rows or so are generally all wrong - any moment when there's a "hole."


The only other thing I can think of is somehow detecting previous rows. I tried that for a bit by using things like array[x][x-1], but could never get anything out of it.

Code:
<table width="100%"  border="1" cellpadding="2" cellspacing="2">
<tr valign="top">
  <td width="10%"></td>
  <td width="12%">Monday<br>01/31</td>
  <td width="12%">Tuesday<br>02/01</td>
  <td width="12%">Wednesday<br>02/02</td>
  <td width="12%">Thursday<br>02/03</td>
  <td width="12%">Friday<br>02/04</td>
  <td width="12%">Saturday<br>02/05</td>
  <td width="12%">Sunday<br>02/06</td>
</tr>

<tr valign="top"><td width="10%">9:00 AM</td> 
  <td width="12%" rowspan="2">array[1][1] - A 1 hour program</a></td>
  <td width="12%" rowspan="1">array[1][2] - A 30 minute program</a></td>
  <td width="12%" rowspan="1">array[1][3] - A 30 minute program</a></td>
  <td width="12%" rowspan="2">array[1][4] - A 1 hour program</a></td>
  <td width="12%" rowspan="1">array[1][5] - A 30 minute program</a></td>
  <td width="12%" rowspan="1">array[1][6] - A 30 minute program</a></td>
  <td width="12%" rowspan="1">array[1][7] - A 30 minute program</a></td>
</tr>
<tr valign="top"><td width="10%">9:30 AM</td> 
  <td width="12%" rowspan="1">array[2][1] - A 30 minute program</a></td>
  <td width="12%" rowspan="2">array[2][2] - A 1 hour program</a></td>
  <td width="12%" rowspan="1">array[2][3] - A 30 minute program</a></td>
  <td width="12%" rowspan="1">array[2][4] - A 30 minute program</a></td>
  <td width="12%" rowspan="2">array[2][5] - A 1 hour program</a></td>
</tr>
<tr valign="top"><td width="10%">10:00 AM</td> 
  <td width="12%" rowspan="1">array[3][1] - A 30 minute program - should be on Thursday 02/03</a></td>
</tr>
</table>

Reply With Quote
  #4  
Old March 22nd, 2005, 02:33 PM
Bastion Bastion is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 181 Bastion User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 23 m 47 sec
Reputation Power: 4
Assuming you haven't checked it already...

Before going further, I would check the logic behind <cfif #TimeArray[a].Date# eq #display_date#> within the innermost loop (the one where index=c) to verify that it is (1) pulling the correct information for both statement parts and (2) definately not going into the else statement. I have a hunch that #TimeArray[a].Date# is causing a problem. Of course, just by looking at this piece, it is only a best guess.

Reply With Quote
  #5  
Old March 22nd, 2005, 04:44 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,611 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 9 h 10 m 21 sec
Reputation Power: 53
Agreed. When it comes to problems in logic like this, the best things to do is strip everything away, start with the first bit of logic, test it until you are 100% sure it is working as you expect, and then add more. Add only one conditional or loop at a time, and only move on when you are sure it is working the way you expect.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #6  
Old March 23rd, 2005, 09:07 AM
midimidi midimidi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 83 midimidi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 29 m
Reputation Power: 4
Quote:
Originally Posted by kiteless
Agreed. When it comes to problems in logic like this, the best things to do is strip everything away, start with the first bit of logic, test it until you are 100% sure it is working as you expect, and then add more. Add only one conditional or loop at a time, and only move on when you are sure it is working the way you expect.



Thanks guys - as mentioned in the last paragraph of my first post, the Date check does not work - I left it in there as the last thing I tried. It enters in empty cells for any row where the current row does not have seven entries - in cases where the previous row has 1 hour items spanning down, this causes problems of extra cells. However, this loop DOES work for the last row showin in my example, where there is only one entry, and nothing is spanning down from the row above it.

If you take out the 1-7 loop, everything works fine, but again, the last entry appears on Monday instead of Thursday. Here is that "bare" code:

Code:
<cfloop index="a" from="1" to="#ArrayLen(TimeArray)#"> <!--- Generally = 35 for 9:00am to 2:30am the day after, in 30 minute increments --->
  <tr valign="top">
  <td width="10%">#TimeFormat(TimeArray[a][1].Time, 'h:mm tt')#</td> <!--- write to 30-min time column --->

  <cfloop index="b" from="1" to="#ArrayLen(TimeArray[a])#"> <!--- loop through data for one 30-min set --->
    <!---write out current element in a cell --->
    <td width="12%" rowspan="#TimeArray[a].Rowspan#">#TimeArray[a].Series#
  </cfloop>
  </tr> <!--- move to next 30 minute row --->
</cfloop>

Reply With Quote
  #7  
Old March 25th, 2005, 07:37 AM
midimidi midimidi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 83 midimidi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 29 m
Reputation Power: 4
Unhappy

Anyone?

Reply With Quote
  #8  
Old March 25th, 2005, 09:43 AM
midimidi midimidi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 83 midimidi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 29 m
Reputation Power: 4
After some more question asking, I've started a new theory to get this working by looking at previous rows.

How can I do math on an array index? i.e.:
Code:
<cfloop index="a" from="1" to="#ArrayLen(TimeArray)#">
  <cfloop index="b" from="1" to="#ArrayLen(TimeArray[a])#">
    <cfloop index="d" from="1" to="4">
      <cfif (a-d) gt "0" and isDefined(TimeArray[a-d][b])>
...etc...etc


...comes back with basically an "Complex object types cannot be converted to simple values" error. Is there any way to do the above?

Reply With Quote
  #9  
Old March 26th, 2005, 11:43 AM
midimidi midimidi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 83 midimidi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 29 m
Reputation Power: 4
OK - still answering my own posts...I have developed some new date logic that "should" work - but I can't figure out how to loope through previous rows of an array. Here's my thought process.

If Date of current program does NOT equal Date to be outputted (i.e. item being looked at is in the wrong column):


Example1:
9:30 AM row, item1
Is there a program at TimeArray[a-1][b] = YES
If Yes, Does it span down? = YES
If Yes, do NOT write empty cell.
- reloop the same item and recheck date

Example2:
11:00 PM Row, item2
Is there a program at TimeArray[a-1][b] = NO
Is there a program at TimeArray[a-2][b] = YES
If Yes, Does it span down? = YES (i.e. going back two rows, the item has a rowspan of 2)
If Yes, do NOT write empty cell.
- reloop the same item and recheck date

Example 3:
2:00 AM Row, item1
Is there a program at TimeArray[a-1][b] = YES
If Yes, Does it span down? = NO
If No, then the previous item does NOT span down, so WRITE an empty cell.
- reloop the same item and recheck date


Here's the code I have in mind as well (look 3 posts up, and add this right after the index=b cfloop) - but again - the TImeArray[a-d][b] does not work. Is there any way at all to do this?

Code:
<cfloop index="c" from="1" to="7">
  <cfif #TimeArray[a][b].Date# neq #display_date#>
  <cfset display_date = DateFormat(DateAdd("d", 1, display_date),"mm/dd/yyyy")>
    <cfloop index="d" from="1" to="4"> <!--- Check rows above, up to 4 rows --->
      <cfif a-d gt "0" and isDefined(TimeArray[a-d][b])>
        <cfif TimeArray[a-d][b].Rowspan eq d+1>
          <!--- END - do not write anything, then restart loop to check date --->
        <cfelse>
          <!--- END - write an empty cell, then restart loop to check date again --->
          <td>nothing!</td>
        </cfif>
      <cfelse> 
        <!--- This is the first row, write out like normal ---->
      </cfif>
    </cfloop>
  <cfelse>
    <!--- Date is correct - Add a Day and goto output --->
    <cfset display_date = DateFormat(DateAdd("d", 1, display_date),"mm/dd/yyyy")>
    <cfbreak>
  </cfif>
</cfloop>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Some logic help needed.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway