mercredi 5 août 2020

Implement complex nested if else logic in Django view

I am having hard time in getting the boolean logic squared away. Here's the flow chart I have attached for your reference.Network_flowchart.

Here's the sample code I have wrote but too me it seems like a complex boolean logic using nested if which i am not so accustomed too. All the variable are entered in the django form and will process the logic based on the values entered. Can any one of you build a psuedo code for this so that i can get the code developed based of that psuedo logic.

    if siteEstimator.is_manufacturing and siteEstimator.throughput_in_mbps > 500:
      
    if siteEstimator.is_manufacturing and siteEstimator.throughput_in_mbps < 500:


    if siteEstimator.rtr1_bandwidth_in_mbps > 200 and siteEstimator.rtr1_bandwidth_in_mbps < 400:
        if siteEstimator.throughput_in_mbps > 200:
           pass
        else:
           pass

    if siteEstimator.rtr1_bandwidth_in_mbps > 100 and siteEstimator.rtr1_bandwidth_in_mbps < 300:
        if siteEstimator.throughput_in_mbps > 100:
           pass
        elif siteEstimator.throughput_in_mbps > 85:
           pass
        else:
           pass

Here's the SiteEstimator models and fields below:

site_name = models.CharField(max_length=50)
no_of_people = models.IntegerField()
is_manufacturing = models.BooleanField(default=False)
no_of_idfs = models.IntegerField()
no_of_small_desktop_switches = models.IntegerField()
does_dmz_exist = models.BooleanField(default=False)
no_of_lab_users = models.IntegerField()
does_firewall_exists = models.BooleanField(default=False)
server_switch = models.IntegerField()
no_of_wireless_aps = models.IntegerField()
rtr1_bandwidth_in_mbps = models.IntegerField()
does_rtr2_exists = models.BooleanField(default=True)
rtr2_bandwidth_in_mbps = models.IntegerField(blank=True, null=True)
# ,  help_text="Only required if 'rtr2 exists checkbox ' is selected.",
throughput_in_mbps = models.IntegerField(blank=True, null=True)
does_wan_optimization_required = models.BooleanField(default=False)
does_voice_gateway_required = models.BooleanField(default=False)
created_date = models.DateTimeField(auto_now_add=True)
modified_date = models.DateTimeField(auto_now=True)

Aucun commentaire:

Enregistrer un commentaire