XXXXXXX

User avatar
Jezza
5StarLounger
Posts: 847
Joined: 24 Jan 2010, 06:35
Location: A Magic Forest in Deepest, Darkest, Kent

XXXXXXX

Post by Jezza »

Jezza Bear sat in bewilderment "Those :censored: buisness people can never make there minds up"

Poor old Jezza had spent a day writing some computer code for a new integration for the Rubbish Bin collection service in the Magic Forest. He was informed by the so called analyst that the collection codes meant this:
AXXXXXX - Mon
XAXXXXX - Tue
XXAXXXX - Wed
XXXAXXX - Thu
XXXXAXX - Fri
XXXXXAX - Sat
XXXXXXA - Sun

Jezza was happy with this so he wrote his XSLT file to read like this

Code: Select all

<xsl:choose>
			<xsl:when test="OccurDay = 'AXXXXXX'">Monday</xsl:when>
			<xsl:when test="OccurDay = 'XAXXXXX'">Tuesday</xsl:when>
			<xsl:when test="OccurDay = 'XXAXXXX'">Wednesday</xsl:when>
			<xsl:when test="OccurDay = 'XXXAXXX'">Thursday</xsl:when>
			<xsl:when test="OccurDay = 'XXXXAXX'">Friday</xsl:when>
			<xsl:when test="OccurDay = 'XXXXXAX'">Saturday</xsl:when>
			<xsl:when test="OccurDay = 'XXXXXXA'">Sunday</xsl:when>
			<xsl:when test="OccurDay =''">By Appointment</xsl:when>
</xsl:choose>
However he went to the UAT session and the analyst said "What is this all about, it is all wrong!"
Jezza Bear went to investigate and he was then informed that the codes could look like this:

ABXXXXX (Collection on Monday and Tuesday)
AXBXXXX (Collection on Monday and Wednesday)
AXXXXBC (Collection on Monday, Saturday and Sunday)
ABCDXXE (Collection everyday apart from Friday and Saturday)
ABCDEFG (Everyday)

Key
A - first collection
B - second collection
.
.
.
.
G - seventh collection

Jezza growled loudly told the analyst that it would be another days coding to which the Analsyt said "Just cut and paste the different combinations into you existing file...easy"

The question is Loungers how combinations of the various from AXXXXXX - ABCDEFG are there?

Happy to answer question if clarification is sought.
Jerry
I’ll be more enthusiastic about encouraging thinking outside the box when there’s evidence of any thinking going on inside it

User avatar
HansV
Administrator
Posts: 78402
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: XXXXXXX

Post by HansV »

Spoiler
27-1 = 127
Best wishes,
Hans

User avatar
Guessed
2StarLounger
Posts: 102
Joined: 04 Feb 2010, 22:44
Location: Melbourne Australia

Re: XXXXXXX

Post by Guessed »

Can you use a mid function something like this...
<xsl:when test="substring(OccurDay,1,1)= 'A'">Monday</xsl:when>
<xsl:when test="substring(OccurDay,2,1)= 'A'">Tuesday</xsl:when>
<xsl:when test="substring(OccurDay,3,1)= 'A'">Wednesday</xsl:when>
Andrew Lockton
Melbourne Australia

User avatar
Jezza
5StarLounger
Posts: 847
Joined: 24 Jan 2010, 06:35
Location: A Magic Forest in Deepest, Darkest, Kent

Re: XXXXXXX

Post by Jezza »

Hi Guessed,

Sadly not, Jezza Bear gave me a call earlier and asked me to help him out so I wrote him this XSLT as we both agreed that the analyst was over-simplifying it

Code: Select all

<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"> 

<xsl:variable name="weekDays" select="'M T W ThF SaS'" />

<xsl:template name="parseYNFlags">
 <xsl:param name="YNFlags"/>
 <xsl:param name="dayAbbreviations" />
 <xsl:choose>
   <xsl:when test="substring($YNFlags, 1, 1) != 'X'" >
     <xsl:value-of select="substring($dayAbbreviations, 1, 2)" />
   </xsl:when>
  <xsl:otherwise>&#160;</xsl:otherwise>
 </xsl:choose>  

 <xsl:if test="string-length($YNFlags) > 1" >
  <xsl:call-template name="parseYNFlags">
    <xsl:with-param name="YNFlags" select="substring($YNFlags, 2)" />
    <xsl:with-param name="dayAbbreviations"
select="substring($dayAbbreviations, 3)" />
  </xsl:call-template>
  </xsl:if>
</xsl:template>




<xsl:template match="/">

<xsl:for-each select="Items/Item">
<table border="0" cellspacing="0" style="width:100%">
 <tr class="columnheader">
  	<td align="left" style="width:40%">Description</td>
  	<td align="left" style="width:20%">Round Code</td> 
   	<td align="left" style="width:40%">Day</td> 	
 </tr>

  
<td><xsl:value-of select="ItemDesc" /></td>
<td><xsl:value-of select="RoundCode"/></td>
<td>
 <xsl:choose>	
  	<xsl:when test="OccurDay =''"><b>By Appointment</b></xsl:when>
  <xsl:otherwise>
    
  	<xsl:variable name="temp" >
  	  <xsl:call-template name="parseYNFlags" >
  	    <xsl:with-param name="YNFlags" select="OccurDay" />
  	    <xsl:with-param name="dayAbbreviations" select="$weekDays" />
  	  </xsl:call-template>
  	</xsl:variable>

  		<xsl:variable name="translatedTemp" select="translate($temp, ' ', '')" />
  		<xsl:value-of select="$translatedTemp" />
</xsl:otherwise>
  </xsl:choose>	
</td>
</table>
</xsl:for-each>
 <xsl:text>*Days subject to change in weeks when there is a Bank Holiday</xsl:text>
</xsl:template>
</xsl:stylesheet>
It is a simply searches the string for any character that is not an X and then replaces it with the equivalent if mid() using substring. We felt it was more efficient than using so many when tests
Jerry
I’ll be more enthusiastic about encouraging thinking outside the box when there’s evidence of any thinking going on inside it

User avatar
Jezza
5StarLounger
Posts: 847
Joined: 24 Jan 2010, 06:35
Location: A Magic Forest in Deepest, Darkest, Kent

Re: XXXXXXX

Post by Jezza »

HansV wrote:
Spoiler
27-1 = 127
I am rather embarrassed as I am not sure what the answer is as this is a real life situation (I think you can guess)
Spoiler
I happily worked out that if it was just A's with multiple week pick ups there would be 28 combinations (because I had a scratch pad and a cup of cocoa[with extra marshmallows])
Jerry
I’ll be more enthusiastic about encouraging thinking outside the box when there’s evidence of any thinking going on inside it

User avatar
HansV
Administrator
Posts: 78402
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: XXXXXXX

Post by HansV »

Spoiler
The letters are obscuring the very simple situation: for every day of the week, there are two states: garbage is collected or garbage is not collected. So the number of possible combinations is 2*2*2*2*2*2*2 = 128. But this includes the situation where garbage isn't collected at all (XXXXXXX in your notation); if I interpret your story correctly, this situation should not be counted, so we're left with 128-1 = 127 combinations.
Best wishes,
Hans

User avatar
John Gray
PlatinumLounger
Posts: 5405
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: XXXXXXX

Post by John Gray »

For those who knew IBM mainframe Assembler language, this would have been an ideal application for the Shift Left Logical and Shift Right Logical instructions, by setting up an 8-bit binary field (like 1000 0110 - last bit unused and thus always zero) and shifting it a certain number of bits left and right to obtain the state of each bit. Even more useful would have been the Test under Mask instruction, where any combination of bits could be tested for on-ness or off-ness.

The coding employed by Mr J Bear above looks almost like Cobol in its prolixity! Sigh - such is progress...
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...