vendredi 25 juin 2021

Incorrectly phrased IF Statement from C++ SDK

I have been using an SDK for Alpaca Markets that was created by another person and released on GitHub. This code contains an IF Statement which does not seem like it is formatted correctly to me, but I am somewhat new to C++. It is pasted below

The if statement does not appear to actually be checking any Boolean values. The code will also fail to compile when this statement is included. The solution I found was to comment it out and set the variables within the config.cpp file.

Is this simply just a mistake?

if (auto e = std::getenv(api_key_id_env_var_.c_str()){
  api_key_id_ = std::str(e);
} else {
  return Status(1, api_key_id_env_var_ + " is not set." 
} 

transforms several rows into several columns in one insert Talend

I need in Talend to be able to read each of the lines and check each of them with a condition. If the condition is met, I associate it with a column in my database.

I have something like that (Input) :

enter image description here

Little error, the last record in col2 would be: Hours pm and not Hours am.

I need something like that (Output) :

enter image description here

So I need to go through each of the lines and tell Talend :

If col1 = 'name' then the value of col2 go to column "col1" of my database

else if col1 = 'phone' then the value of col 2 go to column "col2" of my database

else if col1 = 'address' then the value of col 2 go to column "col3" of my database

else if col1 = 'city' then the value of col 2 go to column "col4" of my database

else if col2 = 'Hours am' then the value of col 1 go to column "col5" of my database

else if col2 = 'Hours pm' then the value of col 1 go to column "col6" of my database

precision: At the end i only need to have 1 row with the values ​​of the columns i need

It is possible to do that with Talend?

Thank you !

How to filter 'If' Statements for File Types (C#) [duplicate]

I have developed my program to use an OpenFileDialog, which then that displays the image selected in a picture box. However, let's say I have 2 pictureboxes, meant for 2 different file types. How do I have the program detect the different file types after the file filter shown, and open it in the different pictureboxes.

For example, the File Filter Searches for file types that are specified in the Image Formats string, but how do I make it so that executes different 'If' Statements for different File Extensions it detects.

(Image Formats string filters out .jpeg and .png files, but how to make different if statements for different file types detected?)

//File Filter System 
        private void BtnMediaPlayer_Click(object sender, EventArgs e)
        {
            // FFS Activation
            var open = new OpenFileDialog();
            open.Filter = OpenFileImageFilter;

            if (open.ShowDialog() == DialogResult.OK)
            {
             
                // IS IT POSSIBLE to have 1 IF Statement for .jpeg, and 1 IF Statement for .png?

                if (IsValidImageFile(open.FileName))
                {
                    // display image in picture box  
                    picturebox1.Image = new Bitmap(open.FileName);
                    
                }

                else
                {
                    MessageBox.Show("Invalid file type selected.");
                }
            }
        }
        private string[] ImageFormats => new[] { ".jpg", ".jpeg", ".png", ".gif" };

        private string OpenFileImageFilter
        {
            get
            {
                string fileExts = "";
                foreach (string s in ImageFormats)
                {
                    fileExts += $"*{s};";
                }
                return $"Image Files({fileExts})|{fileExts}";
            }

        }

        // Utilizies ImagesFormat to Check File Extension
        private bool IsValidImageFile(string filename)
        {
            if (string.IsNullOrEmpty(filename)) return false;
            string extension = Path.GetExtension(filename);
            return ImageFormats.Contains(extension);
        }
        ///

solo learn if else statement determine if triangle is right angled or triangle not

Write a program that takes lengths of triangle sides as inputs, and output whether our triangle is right-angled or not. If the triangle is right-angled, the program should output "Right-angled", and "Not right-angled" if it's not.

side1 = int(input())
side2 = int(input())
side3 = int(input())
if side1**2+side2**2==side3**2:
    print("Right-angled")
    else:
        ("Not right-angled")

Using ifelse() statements to get objects of different classes in R

I want to know how to use ifelse() statements to get different kinds of objects in R.

Specifically, I want to do this with the mtcars data, which is a list type object. I used the code below to create a character object version of the name of the data, called mtcars__string_object.

mtcars__string_object <- c("mtcars")

For the object itself, here is the code I want to use to get this data via an ifelse() statement, which does not work:

test_1 <- 
  ifelse(
    ((typeof(mtcars) == "list") == TRUE),
    (mtcars),
    NA
  )

It does not work because it doesn't give me the dataset in its original form. Here are the results:

> test_1
[[1]]
 [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4
[16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7
[31] 15.0 21.4

When I just use the name of the object, here is the code I want to use to get this data via an ifelse() statement, which does not work:

test_2 <- 
  ifelse(
    ((typeof(mtcars) == "character") == TRUE),
    (get(mtcars__string_object[1])),
    NA
  )

It does not work because it doesn't give me the dataset in its original form. Here are the results:

> test_2
[1] NA

I'm not sure how to fix the code to get the desired result. Please advise. Thanks.



Here is the code that I used for the example:

# StackOverflow materials

## sets up data

### name of object
mtcars

### text object with name of dataset
mtcars__string_object <- c("mtcars")

## checks typeof() of objects
typeof(mtcars)
typeof(mtcars__string_object)

## ifelse() statements to call data

### for object itself
# ---- NOTE: creates object
test_1 <- 
  ifelse(
    ((typeof(mtcars) == "list") == TRUE),
    (mtcars),
    NA
  )
# ---- NOTE: displays object
test_1
# ---- NOTE: does not work

### for text object with name of dataset
# ---- NOTE: creates object
test_2 <- 
  ifelse(
    ((typeof(mtcars) == "character") == TRUE),
    (get(mtcars__string_object[1])),
    NA
  )
# ---- NOTE: displays object
test_2
# ---- NOTE: does not work

Javascript - How to compare property values in objects in an array

I am trying to iterate through the games in team. each game records a score for the team and the opponent. I am trying to show how many games the team has won but i am getting NaN returned.

Please help?

const team = {
  _games: [{
    opponent: 'Banks',
    teamGoals: 5,
    opponentGoals: 3
  },
  {
    opponent: 'Gales',
    teamGoals: 0,
    opponentGoals: 4
  },
  {
    opponent: 'Ingles',
    teamGoals: 6,
    opponentGoals: 0
  }],
  get games() {
    return this._games;
  },

  addGame(opponent, teamGoals, opponentGoals) {
    const newGame = {
      opponent,
      teamGoals,
      opponentGoals,
    };
    this._games.push(newGame);
  },

};

team.addGame('Frankies', '3', '2');
team.addGame('Chippenham', '2', '4');
team.addGame('Gores', '6', '2');

const numberOfGames = team.games.length;

const gamesWon = () => {
  let won;
  for (let x in team.games){
    if(team.games[x].teamGoals > team.games[x].opponentGoals) {
      won += 1;
    };
  };
  console.log(`Team has won ${won} games`)
};

gamesWon();
console.log(`Team has played: ${numberOfGames} games`)

Is there a way I can use the If-Else statement to run this code correctly

Newbie here! I am trying to use the if-else statement to compare a BMI result against the standard BMI threshold. so I tried to create variables that represented the threshold hold for underweight, healthy, overweight and obese. my BMI result is 28.28639. here the code I ran initially:

BMI<-28.28639

underweight<- 10-18.4

healthy<- 18.5-24.9

overweight= 25.0-29.9

obese= 30.0-50.0

if(10<BMI<18.5){print("underweight")}