lundi 27 août 2018

SSRS - Using Expressions with "If" statements and multiple parameter values

So I'm trying to set up some dynamic text for a report in SSRS with 4 user parameter fields and I keep running into the same error. I'm still pretty new to SSRS and Visual Basic, so it's a bit hard to understand the error message.

System.Web.Services.Protocols.SoapException: The Value expression for the textrun 
‘Textbox2.Paragraphs[2].TextRuns[1]’ contains an error: [BC33104] 'If' operator
requires either two or three operands.

The 4 parameter fields are beginYear, beginMonth, endYear, & endMonth. The following is the code I have in the expression:

If (bYear = eYear) And (bMonth = 1) And (eMonth = 3)
"3rd Quarter January - March " & eYear

ElseIf  (bYear = eYear) And (bMonth = 4) And (eMonth = 6)
"4th Quarter April - June " & eYear

ElseIf  (bYear = eYear) And (bMonth = 7) And (eMonth = 9)
"1st Quarter July - September " & eYear

ElseIf  (bYear = eYear) And (bMonth = 10) And (eMonth = 12)
"2nd Quarter October - December " & eYear

ElseIf  (bYear = eYear) And (bMonth = 1) And (eMonth = 12)
"Calendar Year " & eYear

ElseIf  (bYear = eYear) And (bMonth = eMonth)
eYear & " " & eMonth 

ElseIf  (((Convert.toInt32(bYear)) = (Convert.toInt32(eYear)) - 1) And (((Convert.toInt32(eYear)) = (Convert.toInt32(bYear)) + 1) And (bMonth = 7) And (eMonth = 6)
"Fiscal Year " & bYear & "-" & eYear

Else
             bMonth & " " & bYear & "-" & eMonth & " " & eYear
End If

So if I selected the following parameters from the report as follows (in the month parameters, I assigned numerical values to months):

-Begin Year=2018
-Begin Month=April
-End Year=2018
-End Month=June

I should see the following expression in the text box of the report => "4th Quarter April - June 2018"

Selecting one of multiple values that satisfy a condition

So I have this data frame of a condition column and a value column. Suppose I want to change one of the values for which the condition is satisfied, but not all of the values for which the condition is satisfied. The idea here is that I would like to change the values one by one (or select one randomly).

df <- data.frame(condition = c(TRUE,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE),
                 value = 8:1)

I would like to store this in a new column. Suppose I randomly select row 2: The condition is TRUE and the original value is 7. I change it to 0 (or some other value). The desired output in this case is:

> df
condition value
1      TRUE     8
2      TRUE     7
3      TRUE     6
4      TRUE     5
5     FALSE     4
6     FALSE     3
7     FALSE     2
8     FALSE     1

I suppose I could do this with an if statement, a third column of group-row-numbers and the sample function, but is there a nicer way? In particular, I need to make sure I do not generate a new column in case the condition is not satisfied for any of the values. Otherwise I am wasting a lot of computing time later on in the analysis. I usually do things inside the tidyverse if I can, but I do not mind if there is a nice solution without using the package (or using a different package). Thanks!

If chained - how to delete?

I'm doing an application where I have the following scenario:

I have several rules (business classes)

where they all return the client code. They are separate classes that will look for the code trial and error, if find the client code returns it and so on.

How can I use a rule without using a bunch of IFs or threaded IFs in the class that calls the others that contains the specific business rules?

For the specific classes, I used the design pattern strategy.

EX: Main Class

  public abstract class Geral
{
    public abstract string retornaCodigo(Arquivo cliente)
    {
        var codigo = "";   // logica  

        return codigo;
    }

}

//Classe derivada 1


public class derivada1 : Geral
{
    public override string retornaCodigo(Arquivo cliente)
    {

        var codigo = "";  // logica  

        return codigo;
    }

}

//Classe derivada 2



public class derivada2 : Geral
{
    public override string retornaCodigo(Arquivo cliente)
    {

        var codigo = "";    // logica 2 

        return codigo;
    }

}

//Classe derivada 3



public class derivada3 : Geral
{
    public override string retornaCodigo(Arquivo cliente)
     {

         var codigo = "";  // logica 3 

       return codigo ;
     }

}


//Classe de Negocio 



public class Negocio
{

    public string Codigo()
    {
        var arquivo = new Arquivo();
        var derivada1 = new derivada1().retornaCodigo(arquivo);

        var derivada2 = new derivada2().retornaCodigo(arquivo);
        var derivada3 = new derivada3().retornaCodigo(arquivo);


        if (derivada1.Equals(null))
        {
            return derivada1;
        }
        if (derivada2.Equals(null))
        {
            return derivada2;
        }

        if (derivada3.Equals(null))
        {
            return derivada3;
        }
        return "";
    }
}

what I wanted and that I did not have to use Ifs in the Business class for validation whether or not I found the code where it can fall under any condition gave example of 3 classes plus I have more than 15 conditions and can increase, case would be many Ifs.

Code Rewite for tuple and if else statements by using LINQ

In my C# application i am using linq. I need a help what is the syntax for if-elseif- using linq in single line. Here is the code:

        var Date1 = RangeData.ToList();

        foreach (var tr in Date1)
        {
           int id =0;

            if (tr >0)
            {
               id =1;
            }
            else if (tr >3)
            {
               id =2;
            }
            if (id > 0)
            {
                //
            }
        }

shell script missing semicolon in if statement and no syntax error?

Someone pointed out a missing semicolon in a simple shell script and I'm curious why it's not throwing a syntax error.

Full script:

interval () {
    INTERVAL="$*"
    WHEN_TO_RUN=0
    while read LINE; do
        if (( $(epoch 0S) >= $WHEN_TO_RUN )) then
            echo $LINE
            WHEN_TO_RUN="$(epoch $INTERVAL)"
        fi
    done
}

line in question:

if (( $(epoch 0S) >= $WHEN_TO_RUN )) then

I'm also confused as to why the parens make that line work, when I'd normally expect:

if [ $(epoch 0S) -ge $WHEN_TO_RUN ]; then

on OSX if relevant

How to write python code independent of code's position?

I am new in python and using Spyder for scripting. I have some python codes for nested if-else (multiple statements). But the problem is same code may give different outputs if someone shifted the codes. Following is an example of that kind of situation.

num1 = -1
num2 = -2

if(num1 > 0):
    if(num2 < 0):
        print("num1 +ve")
        print("num2 -ve")
elif(num2 < 0):
    print("num1 -ve")
    print("num1 -ve")
else:
    print("num1 -ve")
    print("num2 +ve")

# num1 -ve
# num1 -ve


if(num1 > 0):
    if(num2 < 0):
        print("num1 +ve")
        print("num2 -ve")
    elif(num2 < 0):
        print("num1 -ve")
        print("num1 -ve")
else:
    print("num1 -ve")
    print("num2 +ve")

# num1 -ve
# num2 +ve

Can I use any parenthesis or something like that so that code shift do not effect the output?

filtering data in array

I have an array, of type myClass, got (status, description_1, description_2, .. till 6, duration_1 ... till 6, fromDay_1 to 6, toDay_1 to 6 fromTime_1 to 6 toTime_1 to 6) these data all in String format: data Example:

    "status" : "present",
    "description1": "2P MTR M-F 7:30-16:00",
    "description2": "2P MTR M-F 18:30-20:30",
    "description3": "2P MTR SAT 7:30-20:30",
    "description4": "2P SUN 7:30-18:30",
    "duration1": "120",
    "duration2": "120",
    "duration3": "120",
    "duration4": "120",
    "endtime1": "16:00:00",
    "endtime2": "20:30:00",
    "endtime3": "20:30:00",
    "endtime4": "18:30:00",
    "fromday1": "1",
    "fromday2": "1",
    "fromday3": "6",
    "fromday4": "0",
    "starttime1": "07:30:00",
    "starttime2": "18:30:00",
    "starttime3": "07:30:00",
    "starttime4": "07:30:00",
    "today1": "5",
    "today2": "5",
    "today3": "6",
    "today4": "0"

I have a 3000 data set. I need to output a different result for each set for example :

if (current time between fromTime_1 and toTime_1) and (current week day between fromDay_1 and toDay_1) output: description_1 else if (current time between fromTime_2 and toTime_2) and (current week day between fromDay_2 and toDay_2) output: description_2. and so on for all the 6 conditions.

The other part is I also wanted to display different img on the screen for below conditions:

if (current time between fromTime_1 and toTime_1) and (current week day between fromDay_1 and toDay_1) and status = Unoccupied "but i need to check if the status is = present" and duration_1 = 15 "but duration might be 60 or 120 or 240 and that is output a different img in regarding to the time and the status" output: imgGreen

else if ... same for all 6 conditions. What is the best way to filter my data, I have not much experience in this type of data filtering so please help. Thanks in advance.