jeudi 27 mai 2021

c# asp.net mvc - simplification

how can I simplify this composite condition?

    @if (Model.State.Inventory[0] == true
     && Model.State.Inventory[1] == true
     && Model.State.Inventory[2] == true
     && Model.State.Inventory[3] == true
     && Model.State.Inventory[4] == true
     && Model.State.Inventory[5] == true)
    {
        <a type="button" class="btn btn-secondary" asp-page="Cellar">Go to the Cellar</a>
    }

How to convert -99 value in datetime column to a date of my choosing? [duplicate]

I have some data:

ID Date
1 2021-05-01
2 2021-05-01
3 2021-05-01
4 -99
5 -99
6 2017-11-21
7 -99
8 2019-02-04
9 -99
10 -99

Where I have -99, I want to change it to 2021-05-20. I have tried if statement but it won't work, there are still -99s. I have made sure it is a datetime column although thinking about that -99 isn't a datetime value. Maybe that is where I'm going wrong?

df['Date'] = pd.to_datetime(df['Date'], format='%Y-%m-%d')

if (df['Date'] is '-99'):
    df['Date'] = pd.Series(['2021-05-20' for x in range(len(df.index))])

I'm thinking the length part is wrong too, since there aren't as many -99 as there are data rows. Thanks in advance for the help!

Is there any way to line up data in columns in python?

I have a coding assignment to line up data in columns. print('i i2 i3 2i',sep=' ') for i in range(1,13): print(i, i2,i3,2i,sep=' ') I have written this code. Kindly someone help me to line up data in columns.

How do I make this code work as though the else statement is inexistent when an if is correct, and equally do the same for the else statement

let all = ['Nkechi', 'Añuli', 'Nneka'];

function start(){
  let begin = prompt('Name');
  let counted = "";
  for(let i = 0; i<all.length; i++){
    if(begin === all[i]){
      counted = all[i];
      alert(`Welcome ${counted}`);
    } else {
      alert('Entrance denied');
    }
  }
}

Sorting rectangular objects into a cupboard

So here we are packing objects and Both Length, Width and Height of object should be less than 50 for a good case and if any is more than 50 then the case is bad. I have written my program below but all cases are judged by the last case.

Sample input

2

20 20 20

1 2 51

Sample output

Case 1: good

Case 2: bad

T = int(input("Enter the number of test cases:\n"))
for i in range(1,T+1):
     print("Enter the values of the Length, Width, Height") 
     case = input()

#Length_1.
if case[1] == " ":
     L = int(case[0])
     #Width and heigth.
     if case[3] == " " and len(case) == 5:
          W = int(case[2])
          H = int(case[4])
     if case[4] == " " and len(case) == 6: 
          W = int(case[2:4])
          H = int(case[5])
     if case[3] == " " and len(case) == 6:
          W = int(case[2])
          H = int(case[4:6])
     if case[4] == " " and len(case) == 7:
          W = int(case[2:4])
          H = int(case[5:7])
         
#Length_2.
if case[2] == " ":
     L = int(case[0:2])
     #Width and height.
     if case[4] == " " and len(case) == 6:
          W = int(case[3])
          H = int(case[5])
     if case[5] == " " and len(case) == 7:
          W = int(case[3:5])
          H = int(case[6])
     if case[4] == " " and len(case) == 7:
          W = int(case[3])
          H = int(case[5:7])
     if case[5] == " " and len(case) == 8:
          W = in`enter code here`t(case[3:5])
          H = int(case[6:8])

for i in range(1,T+1):
     if L > 50 or W > 50 or H > 50:
          print("Case ", i,":"," bad", sep='')
     else:
          print("Case ", i,":"," good", sep='')

Having trouble with my reaction test in C# Win Form [duplicate]

I am brand new to programming and have set out to learn C#. I decided to create a reaction speed test, simple "click the box when the colour changes". That all works fine...the only issue I am having is if the user clicks before the screen has changed colour (Stopwatch has started) I get an error.

I understand the error (stopwatch was null), I think! It is being caused because of the if statement trying to stop the stopwatch, when it hasn't yet been started. Problem is I'm not sure of a fix.

Any help would be appreciated, code below.

namespace Reaction_Test
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void InfoLabel_Click(object sender, EventArgs e)
    {

    }


    Timer timer;
    Stopwatch stopwatch;
    bool isTicking;


    private void ReactionButton_Click(object sender, EventArgs e)
    {
        ReactionButton.BackColor = Color.Red; //sets the click area to blue when test has started
        List<double> reactionResult = new();

        //prog crashes when button is click before it turns red, find a way of giving a "too soon" error and change colour

        if (isTicking)
        {

            stopwatch.Stop();
            ReactionButton.BackColor = Color.Aqua;
            TimeLabel.Text = stopwatch.Elapsed.TotalMilliseconds.ToString();
            reactionResult.Add(double.Parse(TimeLabel.Text));

            foreach (double react in reactionResult)
            {
                Debug.WriteLine(react);
            }
            

            isTicking = false;
        }
        else
        {
            Random random = new();
            timer = new();
            timer.Tick += Timer_Tick;
            timer.Interval = random.Next(2000, 7000);
            timer.Start();
            isTicking = true;
        }

        int index = 0;
        foreach (double react in reactionResult)
        {

            double num1 = reactionResult[index];



            if (index + 1 < reactionResult.Count)
            {

                double num2 = reactionResult[index + 1];


            }

            index++;

        }
    }






    private void Timer_Tick(object sender, EventArgs e)
    {
        ReactionButton.BackColor = Color.Green;
        timer.Stop();
        stopwatch = new();
        stopwatch.Start();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void Restart_Click(object sender, EventArgs e)
    {
        this.Controls.Clear();

        this.InitializeComponent();

        timer.Stop();
        isTicking = false;

    }

    private void Exit_Click(object sender, EventArgs e)
    {
        this.Close();
    }

}

}

Either my if statement or parameter doesn't work

Helloo! I have been trying to make a Walmart stock monitor, but I ran into an issue, but realized that redirecting to the desired link again fixes the issue therefore in my code. I try to catch the error that lets me identify the error and then run the original function again, but with the parameter that sets a=1 so that it triggers the if statement causing it to refresh to go to the desired page and check stock again, but its not working how I desired, it appears that the parameter a always gets set to 0 and I have no clue why, id gladly appreciate any help !

const core = require('puppeteer-core');

async function init(a) {
  let b = a;
  console.log(b);
  const browser = await core.launch({
    executablePath: '/Program Files/Google/Chrome/Application/chrome.exe',
    headless: false,
    defaultViewport: null,
    args: [
      '--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
      '--accept-language=en-US,en;q=0.9',
      '--sec-fetch-site=none',
    ],
  });

  const page = (await browser.pages())[0];

  await page.goto(
    'https://www.walmart.com/ip/POP-Rocks-BTS-Jungkook/406893736'
  );
  if (a == 1) {
    reload(page);
    stockChecker();
    console.log(a);
  } else {
    console.log(`testing...${a}`);
    stockChecker(page);
    console.log('LfdlA');
  }
}

async function stockChecker(page) {
  let stock = await page.evaluate(() => {
    let in_out_of_stock = document.querySelector(
      'link[itemprop="availability"]'
    ).href;

    return in_out_of_stock;
  });

  let seller = await page.evaluate(() => {
    let seller = document.querySelector('.seller-name').innerText;
    return seller;
  });

  if (
    stock.toLowerCase().includes('instock') &&
    seller.toLowerCase().includes('walmart')
  ) {
    return console.log('in stock');
  } else {
    return console.log('out of stock');
  }
}

async function reload(page) {
  await page.goto(
    'https://www.walmart.com/ip/POP-Rocks-BTS-Jungkook/406893736'
  );
}

async function run() {
  let a = 0;
  try {
    await init(a);
  } catch (e) {
    if (e.toString().toLowerCase().includes("'href' of null")) {
      a = 1;
      init(a);
      console.log(a);
    } else {
      console.log(e.toString());
    }
  }
}

run(); 

Also I am very new to using puppeteer if you recommend any other web automation frameworks that are better in terms of speed / effectiveness or see any ways for me to refactor my code id gladly appreciate that as well comrades.