jeudi 1 août 2019

sh - unexpected operator in if statement

In the following two lines I get this error?

What is wrong?

Debian Buster

my.sh: 101: [: !=: unexpected operator

my.sh: 103: [: !=: unexpected operator

if [ $CONTINUE != "y" ] && [ "$CONTINUE" != "n" ]; then

elif [ $CONTINUE = "n" ]; then

update

echo "\nContinue downloading? [y/n]"
read CONTINUE

#   Error: Invalid argument
if [ $CONTINUE != "y" ] && [ $CONTINUE != "n" ]; then
    error "Invalid argument"
elif [ $CONTINUE = "n" ]; then
    echo "\nDonwload terminated!"
    exit
fi

how can i combine 2 tables and including if clause into one column

I am pretty new in using SQL and trying to combine 2 tables within APEX ( interactive grid), based on the salary and rate the information to be taken from table X ( which i managed), but i need within the same SQL statement based on the information from column Type, to bring within column percentage if clauses to create the information.

and also within the same SQL statement to have the total which would be (ratehourspercentage).

but it seems i just cant manager to combine so many codes into one correctly, i have tried different ways based on what i have found examples all over, but it seems it will just not work for some reason.


select 
Overtime.ID,
OVERTIME.EMPLOYEE_NUMBER,
OVERTIME.EMPLOYEE_FULL_NAME,
OVERTIME."DATE",
OVERTIME.TYPE,
OVERTIME.HOURS,
EMPLOYEES.RATE,
EMPLOYEES.SALARY,
OVERTIME.PERCENTAGE (CASE
WHEN TYPE = "On Call " THEN "70%"
WHEN TYPE = "On Call PH" THEN "100%"
ELSE "150%"
END),
(Rate*hours*percentage) as total,
OVERTIME.CREATED,
OVERTIME.CREATED_BY
from OVERTIME 
LEFT OUTER JOIN EMPLOYEES
ON OVERTIME.EMPLOYEE_NUMBER = EMPLOYEES.EMPLOYEE_NUMBER
group by Employee_Number


select 
Overtime.ID,
OVERTIME.EMPLOYEE_NUMBER,
OVERTIME.EMPLOYEE_FULL_NAME,
OVERTIME."DATE",
OVERTIME.TYPE,
OVERTIME.HOURS,
EMPLOYEES.RATE,
EMPLOYEES.SALARY,
OVERTIME.PERCENTAGE,
(Rate*hours*percentage) as total,
OVERTIME.CREATED,
OVERTIME.CREATED_BY
from OVERTIME 
LEFT OUTER JOIN EMPLOYEES
ON OVERTIME.EMPLOYEE_NUMBER = EMPLOYEES.EMPLOYEE_NUMBER
WHERE OVERTIME.TYPE LIKE 
 (CASE
   WHEN TYPE = "On Call " THEN "70%"
   WHEN TYPE = "On Call PH" THEN "100%"
   ELSE "150%"
 END);
group by Employee_number

i need to have the percentage information to reflect within the percentage column which i presume should be with if clause

React native error : Statement if does not work

when I want to compare the data entered by user with the data in the database I encounter a problem Unexpected token before the line of if(username == item.username && password == item.password) {.

please, how can I solve this problem? thank you

    login = (username,password) => {
        if (username === null || password === null) {
            alert("Veuillez remplir les champs !");
        }else{
        state ={
        data:[]
        }

        fetchData= async()=>{
            const response = await fetch('http:192.168.42.80:4545/authentification/:username/:password');
            const users = await response.json();
            this.setState({data: users});
        }
        function componentDidMount(){
          this.fetchData();
        }

        <FlatList
            data={this.state.data}
            keyExtractor={(item,index) => index.toString()}
            if(username == item.username && password == item.password) {
                alert(" connecter");
            }else{
                alert("non connecter");
            }
        />

    }
    }

I want to compare between the login and password entered by the user and the information stored in the database

How so simplify Switch Case and if stement?

I am using that switch case to select the index of the foreach, and using and if statement to increment model.Hours1(2,3,4,5...) but know I want to do this for hours100. How can i do?

switch (colNames.IndexOf(item2))
{
    case 0:
        if (model.Hours == null)
        {
            item.Hours = 0;
        }
        else
        {
            item.Hours = (decimal)model.Hours;
            item.Hours_Remaining = (decimal)model.Hours;
        }
        break;

    case 1:
        if (model.Hours1 == null)
        {
            item.Hours = 0;
        }
        else
        {
            item.Hours = (decimal)model.Hours1;
            item.Hours_Remaining = (decimal)model.Hours;
        }
        break;
}

How to form another colum in a pd.DataFrame out of different variables

I'm trying to make a new boolean variable by an if-statement with multiple conditions in other variables. But so far my many tries do not even work with one.

I wanna have a variable "Label" which is whether TRUE or FALSE if the variables "AnzZahlung" is equal or lower than 1 & 'DLZ_SCHDATSCHL' is lower then 20% of the Data, there is only a 15% difference between 'Schadenwert' and 'zahlgesbrut' and 4 extra variables are equal to 'N' (Which is string containing False in this dataset).

I sliced the DataFrame before several times which worked pretty well and I could also create the different variables. I tried different methods with Lambda, list comprehension, writing a function whatever. Even if my Code did run quite fine I just recieved no values for my new variable.

I would really appreciate if anyone of you can see the Problem, I already searched for two days the whole World Wide Web. But as beginner I couldn't find the solution yet.

I sliced the DataFrame before several times which worked pretty well and I could also create the different variables. I tried different methods with Lambda, list comprehension, writing a function whatever.

I would really appreciate if anyone of you can see the Problem, I already searched for two days the whole World Wide Web. But as beginner I couldn't find the solution yet.

amount = df4['AnzZahlungIDAD']
time = df4['DLZ_SCHDATSCHL']
Erstr = df4['Schadenwert']
Zahlges = df4['zahlgesbrut']
timequantil = time.quantile(.2)
diff = (Erstr-Zahlges)/Erstr*100
diffrange = [(diff <=15) & (diff >= -15)]
special = df4[['Taxatoreneinsatz', 'Belegpruefereinsatz_rel', 'IntSVKZ', 'ExtTechSVKZ']]

First Method with list comprehension

label = []
label = [True if (amount[i] <= 1) & (time[i] <= timequantil) & (diff == diffrange) & (special == 'N') else False for i in label]
label

Second Method with iterrows()

df4['label'] = pd.Series([])
df4['label'] = [True if (row[amount] <= 1) & (row[time] <= timequantil) & (row[diff] == diffrange) & (row[special] == 'N') else False for row in df4.iterrows()]
df4['label']

3rd Method with Lambda function

df4.loc[:,'label'] = '1'
df4['label'] = df4['label'].apply([lambda c: True if (c[amount] <= 1) & (c[time] <= timequantil) & (c[diff] == diffrange) & (c[special]) == 'N' else False for c in df4['label']], axis = 0)
df4['label'].value_counts()

I expected that I get a varialbe "Label" in my dataframe df4 that is whether True or False.

Fewer tries gave me only all values = False or all = True even if I used only a single Parameter, which is impossible by the data.

First Method runs fine but Outputs: []

Second Method gives me following error: TypeError: tuple indices must be integers or slices, not Series

Third Method does not load at all.

How to replace multiple "if-else-if" with a map

I am getting one concern on multi layer if-else-if condition so I want to make short by using a map.

Please see below code in if-else-if which I want to replace with a map.

function, args := APIstub.GetFunctionAndParameters()

if function == "queryProduce" {
    return s.queryProduce(APIstub, args)
} else if function == "initLedger" {
    return s.initLedger(APIstub)
} else if function == "createProduce" {
    return s.createProduce(APIstub, args)
} else if function == "queryAllProduces" {
    return s.queryAllProduces(APIstub)
} else if function == "changeProduceStatus" {
    return s.changeProduceStatus(APIstub, args)
}

return shim.Error("Invalid Smart Contract function name.")
}

Check in R if reactive dataframe exists in if statement

I am making a dashboard using R Shiny that has an overview page with a number of charts. All charts are created using the same module. Users can select one subject they want all charts to show, but not all subjects exist for all charts.

Therefore, which certain selections not all charts will show data. In those cases I would like to show a text that tells the user that the subject is not available for that specific chart.

The input for my chart is a dataframe that is only created if the subject exists:

  data_indicator <- reactive({
   req(input$choice %in% data$subject)
    data_indicator <- data %>%
      filter(subject ==  input$choice)
  })

I have made two outputs: one that creates a chart ("plot"), and one that shows a text ("text").

Now I want to check if the dataframe has been created to choose which one to use. I've tried doing this using the following statement:

  output$plot_text <- renderUI({
    if (exists("data_indicator()")){
      output <- highchartOutput(ns("plot"))
     } else {
      output <- div(htmlOutput(ns("text")))
    }
    tagList(output)
  })

But it doesn't work, all charts now show the text, even the ones that should be available.

Does the exists command not work with a reactive dataset? Or is something else wrong?