问:
Airflow resource utilization spikes
We have 32 V-CPUs with 28 GB ram with Local Executor but still airflow is utilizing all the resources and this is resulting in over-utilization of resources which ultimately breaks the system execution.

Below is the output for ps -aux ordered by memory usage.

```<code>   PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
  1336  3.5  0.9 1600620 271644 ?      Ss   Feb18  23:41 /usr/bin/python /usr/local/bin/airflow webs
  9434 32.3  0.9 1835796 267844 ?      Sl   03:09   0:31 [ready] gunicorn: worker [airflow-webserver
 10043  9.1  0.9 1835796 267844 ?      Sl   03:05   0:33 [ready] gunicorn: worker [airflow-webserver
 25397 17.4  0.9 1835796 267844 ?      Sl   03:08   0:30 [ready] gunicorn: worker [airflow-webserver
 30680 13.0  0.9 1835796 267844 ?      Sl   03:06   0:36 [ready] gunicorn: worker [airflow-webserver
 28434 60.5  0.5 1720548 152380 ?      Rl   03:10   0:12 gunicorn: worker [airflow-webserver]
 20202  2.2  0.3 1671280 111316 ?      Sl   03:07   0:04 /usr/bin/python /usr/local/bin/airflow run
 14353  1.9  0.3 1671484 111208 ?      Sl   03:07   0:04 /usr/bin/python /usr/local/bin/airflow run
 14497  1.8  0.3 1671480 111192 ?      Sl   03:07   0:03 /usr/bin/python /usr/local/bin/airflow run
 25170  2.0  0.3 1671024 110964 ?      Sl   03:08   0:03 /usr/bin/python /usr/local/bin/airflow run
 21887  1.8  0.3 1670692 110672 ?      Sl   03:07   0:03 /usr/bin/python /usr/local/bin/airflow run
  5211  4.7  0.3 1670488 110456 ?      Sl   03:09   0:05 /usr/bin/python /usr/local/bin/airflow run
  8819  4.9  0.3 1670140 110264 ?      Sl   03:09   0:04 /usr/bin/python /usr/local/bin/airflow run
  6034  3.9  0.3 1670324 110080 ?      Sl   03:09   0:04 /usr/bin/python /usr/local/bin/airflow run
  8817  4.6  0.3 1670136 110044 ?      Sl   03:09   0:04 /usr/bin/python /usr/local/bin/airflow run
  8829  4.0  0.3 1670076 110012 ?      Sl   03:09   0:04 /usr/bin/python /usr/local/bin/airflow run
 14349  1.6  0.3 1670360 109988 ?      Sl   03:07   0:03 /usr/bin/python /usr/local/bin/airflow run
  8815  3.5  0.3 1670140 109984 ?      Sl   03:09   0:03 /usr/bin/python /usr/local/bin/airflow run
  8917  4.2  0.3 1669980 109980 ?      Sl   03:09   0:04 /usr/bin/python /usr/local/bin/airflow run
</code>```

From the RSS field we can see that the RAM being utilized for web-server is more than 10 GB and per task an average of 1 GB is being used.

The tasks are just for monitoring an end point of a rest API.

Below is the Airflow Configuration file

```<code>[core]
# The home folder for airflow, default is ~/airflow
airflow_home = /airflow
# The folder where your airflow pipelines live, most likely a
# subfolder in a code repository
# This path must be absolute
dags_folder = /airflow/dags
# The folder where airflow should store its log files
# This path must be absolute
base_log_folder = /airflow/logs/
# Airflow can store logs remotely in AWS S3 or Google Cloud Storage. Users
# must supply an Airflow connection id that provides access to the storage
# location.
remote_logging = True
remote_log_conn_id = datalake_gcp_connection
encrypt_s3_logs = False
# Logging level
logging_level = INFO
# Logging class
# Specify the class that will specify the logging configuration
# This class has to be on the python classpath
logging_config_class = log_config.LOGGING_CONFIG
# Log format
log_format = [%%(asctime)s] {%%(filename)s:%%(lineno)d} %%(levelname)s - %%(message)s
simple_log_format = %%(asctime)s %%(levelname)s - %%(message)s
# The executor class that airflow should use. Choices include
# SequentialExecutor, LocalExecutor, CeleryExecutor, DaskExecutor
executor = LocalExecutor
# The SqlAlchemy connection string to the metadata database.
# SqlAlchemy supports many different database engine, more information
# their website
sql_alchemy_conn = mysql://user:pass@127.0.0.1/airflow_db
# The SqlAlchemy pool size is the maximum number of database connections
# in the pool.
sql_alchemy_pool_size = 400

# The SqlAlchemy pool recycle is the number of seconds a connection
# can be idle in the pool before it is invalidated. This config does
# not apply to sqlite.
sql_alchemy_pool_recycle = 3000

# The amount of parallelism = 32
# the max number of task instances that should run simultaneously
# on this airflow installation
parallelism = 64

# The number of task instances allowed to run concurrently by the scheduler
dag_concurrency = 32

# Are DAGs paused by default at creation
dags_are_paused_at_creation = True

# When not using pools, tasks are run in the "default pool",
# whose size is guided by this config element
non_pooled_task_slot_count = 400

# The maximum number of active DAG runs per DAG
max_active_runs_per_dag = 16

# Whether to load the examples that ship with Airflow. It's good to
# get started, but you probably want to set this to False in a production
# environment
load_examples = False

# Where your Airflow plugins are stored
plugins_folder = /airflow/plugins

# Secret key to save connection passwords in the db
fernet_key = <FERNET KEY>

# Whether to disable pickling dags
donot_pickle = False

# How long before timing out a python file import while filling the DagBag
dagbag_import_timeout = 120

# The class to use for running task instances in a subprocess
task_runner = BashTaskRunner

# If set, tasks without a `run_as_user` argument will be run with this user
# Can be used to de-elevate a sudo user running Airflow when executing tasks
default_impersonation =

# What security module to use (for example kerberos):
security =

# Turn unit test mode on (overwrites many configuration options with test
# values at runtime)
unit_test_mode = False

# Name of handler to read task instance logs.
# Default to use file task handler.
task_log_reader = gcs.task

# Whether to enable pickling for xcom (note that this is insecure and allows for
# RCE exploits). This will be deprecated in Airflow 2.0 (be forced to False).
enable_xcom_pickling = True

# When a task is killed forcefully, this is the amount of time in seconds that
# it has to cleanup after it is sent a SIGTERM, before it is SIGKILLED
killed_task_cleanup_time = 60

[cli]
# In what way should the cli access the API. The LocalClient will use the
# database directly, while the json_client will use the api running on the
# webserver
api_client = airflow.api.client.json_client
endpoint_url = http://0.0.0.0:8080

[api]
# How to authenticate users of the API
auth_backend = airflow.api.auth.backend.default

[operators]
# The default owner assigned to each new operator, unless
# provided explicitly or passed via `default_args`
default_owner = Airflow
default_cpus = 1
default_ram = 125
default_disk = 125
default_gpus = 0

[webserver]
# The base url of your website as airflow cannot guess what domain or
# cname you are using. This is used in automated emails that
# airflow sends to point links to the right web server
base_url = http://localhost:8080

authenticate = False
auth_backend = airflow.contrib.auth.backends.password_auth

# The ip specified when starting the web server
web_server_host = 0.0.0.0

# The port on which to run the web server
web_server_port = 8080

# Paths to the SSL certificate and key for the web server. When both are
# provided SSL will be enabled. This does not change the web server port.
web_server_ssl_cert =
web_server_ssl_key =

# Number of seconds the gunicorn webserver waits before timing out on a worker
web_server_worker_timeout = 120

# Number of workers to refresh at a time. When set to 0, worker refresh is
# disabled. When nonzero, airflow periodically refreshes webserver workers by
# bringing up new ones and killing old ones.
worker_refresh_batch_size = 1

# Number of seconds to wait before refreshing a batch of workers.
worker_refresh_interval = 30

# Secret key used to run your flask app
secret_key = temporary_key

# Number of workers to run the Gunicorn web server
workers = 4

# The worker class gunicorn should use. Choices include
# sync (default), eventlet, gevent
worker_class = sync

# Log files for the gunicorn webserver. '-' means log to stderr.
access_logfile = -
error_logfile = -

# Expose the configuration file in the web server
expose_config = False

# Set to true to turn on authentication:
# http://pythonhosted.org/airflow/security.html#web-authentication
#authenticate = False

# Filter the list of dags by owner name (requires authentication to be enabled)
filter_by_owner = False

# Filtering mode. Choices include user (default) and ldapgroup.
# Ldap group filtering requires using the ldap backend
#
# Note that the ldap server needs the "memberOf" overlay to be set up
# in order to user the ldapgroup mode.
owner_mode = user

# Default DAG view.  Valid values are:
# tree, graph, duration, gantt, landing_times
dag_default_view = graph

# Default DAG orientation. Valid values are:
# LR (Left->Right), TB (Top->Bottom), RL (Right->Left), BT (Bottom->Top)
dag_orientation = LR

# Puts the webserver in demonstration mode; blurs the names of Operators for
# privacy.
demo_mode = False

# The amount of time (in secs) webserver will wait for initial handshake
# while fetching logs from other worker machine
log_fetch_timeout_sec = 5

# By default, the webserver shows paused DAGs. Flip this to hide paused
# DAGs by default
hide_paused_dags_by_default = True

# Consistent page size across all listing views in the UI
page_size = 40

[email]
email_backend = airflow.utils.email.send_email_smtp

[smtp]
# If you want airflow to send emails on retries, failure, and you want to use
# the airflow.utils.email.send_email_smtp function, you have to configure an
# smtp server here
smtp_host = smtp.gmail.com
smtp_starttls = True
smtp_ssl = False
# Uncomment and set the user/pass settings if you want to use SMTP AUTH
#smtp_user = airflow
#smtp_password = airflow
smtp_port = 25
smtp_mail_from = airflow@example.com

[celery]
# This section only applies if you are using the CeleryExecutor in
# [core] section above

# The app name that will be used by celery
celery_app_name = airflow.executors.celery_executor

# The concurrency that will be used when starting workers with the
# "airflow worker" command. This defines the number of task instances that
# a worker will take, so size up your workers based on the resources on
# your worker box and the nature of your tasks
celeryd_concurrency = 16

# When you start an airflow worker, airflow starts a tiny web server
# subprocess to serve the workers local log files to the airflow main
# web server, who then builds pages and sends them to users. This defines
# the port on which the logs are served. It needs to be unused, and open
# visible from the main web server to connect into the workers.
worker_log_server_port = 8793

# The Celery broker URL. Celery supports RabbitMQ, Redis and experimentally
# a sqlalchemy database. Refer to the Celery documentation for more
# information.
broker_url = sqla+mysql://user:pass@127.0.0.1/airflow_db

# Another key Celery setting
celery_result_backend = db+mysql://user:pass@127.0.0.1/airflow_db

# Celery Flower is a sweet UI for Celery. Airflow has a shortcut to start
# it `airflow flower`. This defines the IP that Celery Flower runs on
flower_host = 0.0.0.0

# This defines the port that Celery Flower runs on
flower_port = 5555

# Default queue that tasks get assigned to and that worker listen on.
default_queue = default

# Import path for celery configuration options
celery_config_options = airflow.config_templates.default_celery.DEFAULT_CELERY_CONFIG

[dask]
# This section only applies if you are using the DaskExecutor in
# [core] section above

# The IP address and port of the Dask cluster's scheduler.
cluster_address = 127.0.0.1:8786

[scheduler]
# Task instances listen for external kill signal (when you clear tasks
# from the CLI or the UI), this defines the frequency at which they should
# listen (in seconds).
job_heartbeat_sec = 20

# The scheduler constantly tries to trigger new tasks (look at the
# scheduler section in the docs for more information). This defines
# how often the scheduler should run (in seconds).
scheduler_heartbeat_sec = 60

# after how much time should the scheduler terminate in seconds
# -1 indicates to run continuously (see also num_runs)
run_duration = -1

# after how much time a new DAGs should be picked up from the filesystem
min_file_process_interval = 5

dag_dir_list_interval = 300

# How often should stats be printed to the logs
print_stats_interval = 30

child_process_log_directory = /airflow/logs/scheduler

# Local task jobs periodically heartbeat to the DB. If the job has
# not heartbeat in this many seconds, the scheduler will mark the
# associated task instance as failed and will re-schedule the task.
scheduler_zombie_task_threshold = 300

# Turn off scheduler catchup by setting this to False.
# Default behavior is unchanged and
# Command Line Backfills still work, but the scheduler
# will not do scheduler catchup if this is False,
# however it can be set on a per DAG basis in the
# DAG definition (catchup)
catchup_by_default = False

# This changes the batch size of queries in the scheduling main loop.
# This depends on query length limits and how long you are willing to hold locks.
# 0 for no limit
max_tis_per_query = 256

# Statsd (https://github.com/etsy/statsd) integration settings
statsd_on = False
statsd_host = localhost
statsd_port = 8125
statsd_prefix = airflow

# The scheduler can run multiple threads in parallel to schedule dags.
# This defines how many threads will run.
max_threads = 12

authenticate = False

[ldap]
# set this to ldaps://<your.ldap.server>:<port>
uri =
user_filter = objectClass=*
user_name_attr = uid
group_member_attr = memberOf
superuser_filter =
data_profiler_filter =
bind_user = cn=Manager,dc=example,dc=com
bind_password = insecure
basedn = dc=example,dc=com
cacert = /etc/ca/ldap_ca.crt
search_scope = LEVEL

[mesos]
# Mesos master address which MesosExecutor will connect to.
master = localhost:5050

# The framework name which Airflow scheduler will register itself as on mesos
framework_name = Airflow

# Number of cpu cores required for running one task instance using
# 'airflow run <dag_id> <task_id> <execution_date> --local -p <pickle_id>'
# command on a mesos slave
task_cpu = 1

# Memory in MB required for running one task instance using
# 'airflow run <dag_id> <task_id> <execution_date> --local -p <pickle_id>'
# command on a mesos slave
task_memory = 256

# Enable framework checkpointing for mesos
# See http://mesos.apache.org/documentation/latest/slave-recovery/
checkpoint = False

# Failover timeout in milliseconds.
# When checkpointing is enabled and this option is set, Mesos waits
# until the configured timeout for
# the MesosExecutor framework to re-register after a failover. Mesos
# shuts down running tasks if the
# MesosExecutor framework fails to re-register within this timeframe.
# failover_timeout = 604800

# Enable framework authentication for mesos
# See http://mesos.apache.org/documentation/latest/configuration/
authenticate = False

# Mesos credentials, if authentication is enabled
# default_principal = admin
# default_secret = admin

[kerberos]
ccache = /tmp/airflow_krb5_ccache
# gets augmented with fqdn
principal = airflow
reinit_frequency = 3600
kinit_path = kinit
keytab = airflow.keytab

[github_enterprise]
api_rev = v3

[admin]
# UI to hide sensitive variable fields when set to True
hide_sensitive_variable_fields = True
</code>```

What are we doing wrong here?

答:
A recommended method is to set the CPUQuota of Airflow to max 80%. This will ensure that Airflow process does not eat up all the CPU resources which sometimes cause the system to hang.

You can use a ready-made AMI (namely, LightningFLow) from AWS Marketplace which is pre-configured with the recommended configurations.

Note: LightningFlow also comes pre-integrated with all required libraries, Livy, custom operators, and local Spark cluster.

Link for AWS Marketplace: https://aws.amazon.com/marketplace/pp/Lightning-Analytics-Inc-LightningFlow-Integrated-o/B084BSD66V

Title: Airflow resource utilization spikes

Body:
We have 32 V-CPUs with 28 GB ram with Local Executor but still airflow is utilizing all the resources and this is resulting in over-utilization of resources which ultimately breaks the system execution.

Below is the output for ps -aux ordered by memory usage.

   PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
  1336  3.5  0.9 1600620 271644 ?      Ss   Feb18  23:41 /usr/bin/python /usr/local/bin/airflow webs
  9434 32.3  0.9 1835796 267844 ?      Sl   03:09   0:31 [ready] gunicorn: worker [airflow-webserver
 10043  9.1  0.9 1835796 267844 ?      Sl   03:05   0:33 [ready] gunicorn: worker [airflow-webserver
 25397 17.4  0.9 1835796 267844 ?      Sl   03:08   0:30 [ready] gunicorn: worker [airflow-webserver
 30680 13.0  0.9 1835796 267844 ?      Sl   03:06   0:36 [ready] gunicorn: worker [airflow-webserver
 28434 60.5  0.5 1720548 152380 ?      Rl   03:10   0:12 gunicorn: worker [airflow-webserver]
 20202  2.2  0.3 1671280 111316 ?      Sl   03:07   0:04 /usr/bin/python /usr/local/bin/airflow run
 14353  1.9  0.3 1671484 111208 ?      Sl   03:07   0:04 /usr/bin/python /usr/local/bin/airflow run
 14497  1.8  0.3 1671480 111192 ?      Sl   03:07   0:03 /usr/bin/python /usr/local/bin/airflow run
 25170  2.0  0.3 1671024 110964 ?      Sl   03:08   0:03 /usr/bin/python /usr/local/bin/airflow run
 21887  1.8  0.3 1670692 110672 ?      Sl   03:07   0:03 /usr/bin/python /usr/local/bin/airflow run
  5211  4.7  0.3 1670488 110456 ?      Sl   03:09   0:05 /usr/bin/python /usr/local/bin/airflow run
  8819  4.9  0.3 1670140 110264 ?      Sl   03:09   0:04 /usr/bin/python /usr/local/bin/airflow run
  6034  3.9  0.3 1670324 110080 ?      Sl   03:09   0:04 /usr/bin/python /usr/local/bin/airflow run
  8817  4.6  0.3 1670136 110044 ?      Sl   03:09   0:04 /usr/bin/python /usr/local/bin/airflow run
  8829  4.0  0.3 1670076 110012 ?      Sl   03:09   0:04 /usr/bin/python /usr/local/bin/airflow run
 14349  1.6  0.3 1670360 109988 ?      Sl   03:07   0:03 /usr/bin/python /usr/local/bin/airflow run
  8815  3.5  0.3 1670140 109984 ?      Sl   03:09   0:03 /usr/bin/python /usr/local/bin/airflow run
  8917  4.2  0.3 1669980 109980 ?      Sl   03:09   0:04 /usr/bin/python /usr/local/bin/airflow run

From the RSS field we can see that the RAM being utilized for web-server is more than 10 GB and per task an average of 1 GB is being used.

The tasks are just for monitoring an end point of a rest API.

Below is the Airflow Configuration file

[core]
# The home folder for airflow, default is ~/airflow
airflow_home = /airflow
# The folder where your airflow pipelines live, most likely a
# subfolder in a code repository
# This path must be absolute
dags_folder = /airflow/dags
# The folder where airflow should store its log files
# This path must be absolute
base_log_folder = /airflow/logs/
# Airflow can store logs remotely in AWS S3 or Google Cloud Storage. Users
# must supply an Airflow connection id that provides access to the storage
# location.
remote_logging = True
remote_log_conn_id = datalake_gcp_connection
encrypt_s3_logs = False
# Logging level
logging_level = INFO
# Logging class
# Specify the class that will specify the logging configuration
# This class has to be on the python classpath
logging_config_class = log_config.LOGGING_CONFIG
# Log format
log_format = [%%(asctime)s] {%%(filename)s:%%(lineno)d} %%(levelname)s - %%(message)s
simple_log_format = %%(asctime)s %%(levelname)s - %%(message)s
# The executor class that airflow should use. Choices include
# SequentialExecutor, LocalExecutor, CeleryExecutor, DaskExecutor
executor = LocalExecutor
# The SqlAlchemy connection string to the metadata database.
# SqlAlchemy supports many different database engine, more information
# their website
sql_alchemy_conn = mysql://user:pass@127.0.0.1/airflow_db
# The SqlAlchemy pool size is the maximum number of database connections
# in the pool.
sql_alchemy_pool_size = 400

# The SqlAlchemy pool recycle is the number of seconds a connection
# can be idle in the pool before it is invalidated. This config does
# not apply to sqlite.
sql_alchemy_pool_recycle = 3000

# The amount of parallelism = 32
# the max number of task instances that should run simultaneously
# on this airflow installation
parallelism = 64

# The number of task instances allowed to run concurrently by the scheduler
dag_concurrency = 32

# Are DAGs paused by default at creation
dags_are_paused_at_creation = True

# When not using pools, tasks are run in the "default pool",
# whose size is guided by this config element
non_pooled_task_slot_count = 400

# The maximum number of active DAG runs per DAG
max_active_runs_per_dag = 16

# Whether to load the examples that ship with Airflow. It's good to
# get started, but you probably want to set this to False in a production
# environment
load_examples = False

# Where your Airflow plugins are stored
plugins_folder = /airflow/plugins

# Secret key to save connection passwords in the db
fernet_key = <FERNET KEY>

# Whether to disable pickling dags
donot_pickle = False

# How long before timing out a python file import while filling the DagBag
dagbag_import_timeout = 120

# The class to use for running task instances in a subprocess
task_runner = BashTaskRunner

# If set, tasks without a `run_as_user` argument will be run with this user
# Can be used to de-elevate a sudo user running Airflow when executing tasks
default_impersonation =

# What security module to use (for example kerberos):
security =

# Turn unit test mode on (overwrites many configuration options with test
# values at runtime)
unit_test_mode = False

# Name of handler to read task instance logs.
# Default to use file task handler.
task_log_reader = gcs.task

# Whether to enable pickling for xcom (note that this is insecure and allows for
# RCE exploits). This will be deprecated in Airflow 2.0 (be forced to False).
enable_xcom_pickling = True

# When a task is killed forcefully, this is the amount of time in seconds that
# it has to cleanup after it is sent a SIGTERM, before it is SIGKILLED
killed_task_cleanup_time = 60

[cli]
# In what way should the cli access the API. The LocalClient will use the
# database directly, while the json_client will use the api running on the
# webserver
api_client = airflow.api.client.json_client
endpoint_url = http://0.0.0.0:8080

[api]
# How to authenticate users of the API
auth_backend = airflow.api.auth.backend.default

[operators]
# The default owner assigned to each new operator, unless
# provided explicitly or passed via `default_args`
default_owner = Airflow
default_cpus = 1
default_ram = 125
default_disk = 125
default_gpus = 0

[webserver]
# The base url of your website as airflow cannot guess what domain or
# cname you are using. This is used in automated emails that
# airflow sends to point links to the right web server
base_url = http://localhost:8080

authenticate = False
auth_backend = airflow.contrib.auth.backends.password_auth

# The ip specified when starting the web server
web_server_host = 0.0.0.0

# The port on which to run the web server
web_server_port = 8080

# Paths to the SSL certificate and key for the web server. When both are
# provided SSL will be enabled. This does not change the web server port.
web_server_ssl_cert =
web_server_ssl_key =

# Number of seconds the gunicorn webserver waits before timing out on a worker
web_server_worker_timeout = 120

# Number of workers to refresh at a time. When set to 0, worker refresh is
# disabled. When nonzero, airflow periodically refreshes webserver workers by
# bringing up new ones and killing old ones.
worker_refresh_batch_size = 1

# Number of seconds to wait before refreshing a batch of workers.
worker_refresh_interval = 30

# Secret key used to run your flask app
secret_key = temporary_key

# Number of workers to run the Gunicorn web server
workers = 4

# The worker class gunicorn should use. Choices include
# sync (default), eventlet, gevent
worker_class = sync

# Log files for the gunicorn webserver. '-' means log to stderr.
access_logfile = -
error_logfile = -

# Expose the configuration file in the web server
expose_config = False

# Set to true to turn on authentication:
# http://pythonhosted.org/airflow/security.html#web-authentication
#authenticate = False

# Filter the list of dags by owner name (requires authentication to be enabled)
filter_by_owner = False

# Filtering mode. Choices include user (default) and ldapgroup.
# Ldap group filtering requires using the ldap backend
#
# Note that the ldap server needs the "memberOf" overlay to be set up
# in order to user the ldapgroup mode.
owner_mode = user

# Default DAG view.  Valid values are:
# tree, graph, duration, gantt, landing_times
dag_default_view = graph

# Default DAG orientation. Valid values are:
# LR (Left->Right), TB (Top->Bottom), RL (Right->Left), BT (Bottom->Top)
dag_orientation = LR

# Puts the webserver in demonstration mode; blurs the names of Operators for
# privacy.
demo_mode = False

# The amount of time (in secs) webserver will wait for initial handshake
# while fetching logs from other worker machine
log_fetch_timeout_sec = 5

# By default, the webserver shows paused DAGs. Flip this to hide paused
# DAGs by default
hide_paused_dags_by_default = True

# Consistent page size across all listing views in the UI
page_size = 40

[email]
email_backend = airflow.utils.email.send_email_smtp

[smtp]
# If you want airflow to send emails on retries, failure, and you want to use
# the airflow.utils.email.send_email_smtp function, you have to configure an
# smtp server here
smtp_host = smtp.gmail.com
smtp_starttls = True
smtp_ssl = False
# Uncomment and set the user/pass settings if you want to use SMTP AUTH
#smtp_user = airflow
#smtp_password = airflow
smtp_port = 25
smtp_mail_from = airflow@example.com

[celery]
# This section only applies if you are using the CeleryExecutor in
# [core] section above

# The app name that will be used by celery
celery_app_name = airflow.executors.celery_executor

# The concurrency that will be used when starting workers with the
# "airflow worker" command. This defines the number of task instances that
# a worker will take, so size up your workers based on the resources on
# your worker box and the nature of your tasks
celeryd_concurrency = 16

# When you start an airflow worker, airflow starts a tiny web server
# subprocess to serve the workers local log files to the airflow main
# web server, who then builds pages and sends them to users. This defines
# the port on which the logs are served. It needs to be unused, and open
# visible from the main web server to connect into the workers.
worker_log_server_port = 8793

# The Celery broker URL. Celery supports RabbitMQ, Redis and experimentally
# a sqlalchemy database. Refer to the Celery documentation for more
# information.
broker_url = sqla+mysql://user:pass@127.0.0.1/airflow_db

# Another key Celery setting
celery_result_backend = db+mysql://user:pass@127.0.0.1/airflow_db

# Celery Flower is a sweet UI for Celery. Airflow has a shortcut to start
# it `airflow flower`. This defines the IP that Celery Flower runs on
flower_host = 0.0.0.0

# This defines the port that Celery Flower runs on
flower_port = 5555

# Default queue that tasks get assigned to and that worker listen on.
default_queue = default

# Import path for celery configuration options
celery_config_options = airflow.config_templates.default_celery.DEFAULT_CELERY_CONFIG

[dask]
# This section only applies if you are using the DaskExecutor in
# [core] section above

# The IP address and port of the Dask cluster's scheduler.
cluster_address = 127.0.0.1:8786

[scheduler]
# Task instances listen for external kill signal (when you clear tasks
# from the CLI or the UI), this defines the frequency at which they should
# listen (in seconds).
job_heartbeat_sec = 20

# The scheduler constantly tries to trigger new tasks (look at the
# scheduler section in the docs for more information). This defines
# how often the scheduler should run (in seconds).
scheduler_heartbeat_sec = 60

# after how much time should the scheduler terminate in seconds
# -1 indicates to run continuously (see also num_runs)
run_duration = -1

# after how much time a new DAGs should be picked up from the filesystem
min_file_process_interval = 5

dag_dir_list_interval = 300

# How often should stats be printed to the logs
print_stats_interval = 30

child_process_log_directory = /airflow/logs/scheduler

# Local task jobs periodically heartbeat to the DB. If the job has
# not heartbeat in this many seconds, the scheduler will mark the
# associated task instance as failed and will re-schedule the task.
scheduler_zombie_task_threshold = 300

# Turn off scheduler catchup by setting this to False.
# Default behavior is unchanged and
# Command Line Backfills still work, but the scheduler
# will not do scheduler catchup if this is False,
# however it can be set on a per DAG basis in the
# DAG definition (catchup)
catchup_by_default = False

# This changes the batch size of queries in the scheduling main loop.
# This depends on query length limits and how long you are willing to hold locks.
# 0 for no limit
max_tis_per_query = 256

# Statsd (https://github.com/etsy/statsd) integration settings
statsd_on = False
statsd_host = localhost
statsd_port = 8125
statsd_prefix = airflow

# The scheduler can run multiple threads in parallel to schedule dags.
# This defines how many threads will run.
max_threads = 12

authenticate = False

[ldap]
# set this to ldaps://<your.ldap.server>:<port>
uri =
user_filter = objectClass=*
user_name_attr = uid
group_member_attr = memberOf
superuser_filter =
data_profiler_filter =
bind_user = cn=Manager,dc=example,dc=com
bind_password = insecure
basedn = dc=example,dc=com
cacert = /etc/ca/ldap_ca.crt
search_scope = LEVEL

[mesos]
# Mesos master address which MesosExecutor will connect to.
master = localhost:5050

# The framework name which Airflow scheduler will register itself as on mesos
framework_name = Airflow

# Number of cpu cores required for running one task instance using
# 'airflow run <dag_id> <task_id> <execution_date> --local -p <pickle_id>'
# command on a mesos slave
task_cpu = 1

# Memory in MB required for running one task instance using
# 'airflow run <dag_id> <task_id> <execution_date> --local -p <pickle_id>'
# command on a mesos slave
task_memory = 256

# Enable framework checkpointing for mesos
# See http://mesos.apache.org/documentation/latest/slave-recovery/
checkpoint = False

# Failover timeout in milliseconds.
# When checkpointing is enabled and this option is set, Mesos waits
# until the configured timeout for
# the MesosExecutor framework to re-register after a failover. Mesos
# shuts down running tasks if the
# MesosExecutor framework fails to re-register within this timeframe.
# failover_timeout = 604800

# Enable framework authentication for mesos
# See http://mesos.apache.org/documentation/latest/configuration/
authenticate = False

# Mesos credentials, if authentication is enabled
# default_principal = admin
# default_secret = admin

[kerberos]
ccache = /tmp/airflow_krb5_ccache
# gets augmented with fqdn
principal = airflow
reinit_frequency = 3600
kinit_path = kinit
keytab = airflow.keytab

[github_enterprise]
api_rev = v3

[admin]
# UI to hide sensitive variable fields when set to True
hide_sensitive_variable_fields = True

What are we doing wrong here?


来源: stackexchange

问:
Fabricjs - selection only via border
I'm using Fabric.js to draw some rectangles on a canvas. The default behavior is that clicking inside a rectangle selects it. How can I change the behavior such that it is only selected when clicking on the border of the rectangle?

Clicking inside the rectangle but not on the border should do nothing.

You can see this behavior by drawing a rectangle on a TradingView.com chart

It there an option for this in fabric, and if not how could I go around implementing it?

答:
Fabric.js uses Object.containsPoint() to determine whether a mouse event should target the object. This method, in turn, calculates the object's edges via Object._getImageLines() and checks how many times the projection of a mouse pointer crossed those lines.

The solution below calculates additional inner edges based on the coordinates of each corner, therefore object scale and rotation are taken care of automatically.

const canvas = new fabric.Canvas('c', {
  enableRetinaScaling: true
})

const rect = new fabric.Rect({
  left: 0,
  top: 0,
  width: 100,
  height: 100,
  dragBorderWidth: 15, // this is the custom attribute we've introduced
})

function innerCornerPoint(start, end, offset) {
  // vector length
  const l = start.distanceFrom(end)
  // unit vector
  const uv = new fabric.Point((end.x - start.x) / l, (end.y - start.y) / l)
  // point on the vector at a given offset but no further than side length
  const p = start.add(uv.multiply(Math.min(offset, l)))
  // rotate point
  return fabric.util.rotatePoint(p, start, fabric.util.degreesToRadians(45))
}

rect._getInnerBorderLines = function(c) {
  // the actual offset from outer corner is the length of a hypotenuse of a right triangle with border widths as 2 sides
  const offset = Math.sqrt(2 * (this.dragBorderWidth ** 2))
  // find 4 inner corners as offsets rotated 45 degrees CW
  const newCoords = {
    tl: innerCornerPoint(c.tl, c.tr, offset),
    tr: innerCornerPoint(c.tr, c.br, offset),
    br: innerCornerPoint(c.br, c.bl, offset),
    bl: innerCornerPoint(c.bl, c.tl, offset),
  }
  return this._getImageLines(newCoords)
}

rect.containsPoint = function(point, lines, absolute, calculate) {
  const coords = calculate ? this.calcCoords(absolute) : absolute ? this.aCoords : this.oCoords
  lines = lines || this._getImageLines(coords)
  const innerRectPoints = this._findCrossPoints(point, lines);
  const innerBorderPoints = this._findCrossPoints(point, this._getInnerBorderLines(coords))
  // calculate intersections
  return innerRectPoints === 1 && innerBorderPoints !== 1
}

canvas.add(rect)```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js"></script>
<canvas id="c" width="400" height="300"></canvas></code>```

ContentLicense: CC BY-SA 4.0

Title: Fabricjs - selection only via border

Body:
Fabric.js uses Object.containsPoint() to determine whether a mouse event should target the object. This method, in turn, calculates the object's edges via Object._getImageLines() and checks how many times the projection of a mouse pointer crossed those lines.

The solution below calculates additional inner edges based on the coordinates of each corner, therefore object scale and rotation are taken care of automatically.

const canvas = new fabric.Canvas('c', {
  enableRetinaScaling: true
})

const rect = new fabric.Rect({
  left: 0,
  top: 0,
  width: 100,
  height: 100,
  dragBorderWidth: 15, // this is the custom attribute we've introduced
})

function innerCornerPoint(start, end, offset) {
  // vector length
  const l = start.distanceFrom(end)
  // unit vector
  const uv = new fabric.Point((end.x - start.x) / l, (end.y - start.y) / l)
  // point on the vector at a given offset but no further than side length
  const p = start.add(uv.multiply(Math.min(offset, l)))
  // rotate point
  return fabric.util.rotatePoint(p, start, fabric.util.degreesToRadians(45))
}

rect._getInnerBorderLines = function(c) {
  // the actual offset from outer corner is the length of a hypotenuse of a right triangle with border widths as 2 sides
  const offset = Math.sqrt(2 * (this.dragBorderWidth ** 2))
  // find 4 inner corners as offsets rotated 45 degrees CW
  const newCoords = {
    tl: innerCornerPoint(c.tl, c.tr, offset),
    tr: innerCornerPoint(c.tr, c.br, offset),
    br: innerCornerPoint(c.br, c.bl, offset),
    bl: innerCornerPoint(c.bl, c.tl, offset),
  }
  return this._getImageLines(newCoords)
}

rect.containsPoint = function(point, lines, absolute, calculate) {
  const coords = calculate ? this.calcCoords(absolute) : absolute ? this.aCoords : this.oCoords
  lines = lines || this._getImageLines(coords)
  const innerRectPoints = this._findCrossPoints(point, lines);
  const innerBorderPoints = this._findCrossPoints(point, this._getInnerBorderLines(coords))
  // calculate intersections
  return innerRectPoints === 1 && innerBorderPoints !== 1
}

canvas.add(rect)

<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js"></script>
<canvas id="c" width="400" height="300"></canvas>


问:
How to pass search parameter, into function that will search a c# collection
Assume I have a collection of the form:

```<code>List<Member> myMembers= new List<Member>()
{
    new Member(){ID=1,FirstName="John",LastName="Doe"},
    new Member(){ID=3,FirstName="Allan",LastName="Jones"},
    new Member(){ID=2,FirstName="Martin",LastName="Moe"},
    new Member(){ID=4,FirstName="Ludwig",LastName="Issac"}
};
</code>```

I can sort this list via FirstName by using:

```<code>myMembers.Sort((x, y) => x.FirstName.CompareTo(y.FirstName));
</code>```

I would like to do this inside of a function, so that I can pass the desired search parameter.  Something like:

```<code>public void sortCollection( parameter SearchTerm, List<Member> myCollection )
{
    myCollection ((x, y) => x.SearchTerm.CompareTo(y.FirstName));
}
</code>```

Obviously here, I cannot pass in the desired search field this way, but is it possible to do what I am asking?

答:
Instead of writing one more wrapper on Linq .OrderBy() or .Sort() method and calling that where ever you want to sort, use Linq OrderBy() or .Sort() method

Use Sort() like

```<code>//If you want to sort collection by Id then
myMembers.Sort(x => x.Id);

//If you want to sort collection by FirstName then
myMembers.Sort(x => x.FirstName);

...
</code>```

To decide between OrderBy()/Sort() read below Q&A thread

C# Sort and OrderBy comparison

Body:
Assume I have a collection of the form:

List<Member> myMembers= new List<Member>()
{
    new Member(){ID=1,FirstName="John",LastName="Doe"},
    new Member(){ID=3,FirstName="Allan",LastName="Jones"},
    new Member(){ID=2,FirstName="Martin",LastName="Moe"},
    new Member(){ID=4,FirstName="Ludwig",LastName="Issac"}
};

I can sort this list via FirstName by using:

myMembers.Sort((x, y) => x.FirstName.CompareTo(y.FirstName));

I would like to do this inside of a function, so that I can pass the desired search parameter.  Something like:

public void sortCollection( parameter SearchTerm, List<Member> myCollection )
{
    myCollection ((x, y) => x.SearchTerm.CompareTo(y.FirstName));
}

Obviously here, I cannot pass in the desired search field this way, but is it possible to do what I am asking?

Body:
Instead of writing one more wrapper on Linq .OrderBy() or .Sort() method and calling that where ever you want to sort, use Linq OrderBy() or .Sort() method

Use Sort() like

//If you want to sort collection by Id then
myMembers.Sort(x => x.Id);

//If you want to sort collection by FirstName then
myMembers.Sort(x => x.FirstName);

...

To decide between OrderBy()/Sort() read below Q&A thread

C# Sort and OrderBy comparison


问:
Python NameError: name 'file_list' is not defined while renaming filenames
I'm very new to Python programming.

And I'm trying to rename filenames inside a folder, so that new filenames will not have any number. E.g. if filename is 123abc.txt then new filename will be abc.txt. The code I've used is below but it is giving error

NameError: name 'file_list' is not defined.

Can someone please help, what mistake I've made?

```<code>import os
def rename_files():
    #Step-1 get file names from a folder
    file_list = os.listdir(r"C:\Users\test\PycharmProjects\proj1")
    print(file_list)
saved_path = os.getcwd()
print("Current working directory is " + saved_path)
        #Current working directory is C:\Users\test\PycharmProjects\proj1
os.chdir(r"C:\Users\test\PycharmProjects\proj1")
    #Step-2 for each filename, rename filename
for file_name in file_list:
    print("Old Name - "+file_name)
    print("New Name - "+file_name.translate(None, "0123456789"))
    os.rename(file_name, file_name.translate(None, "0123456789"))
os.chdir(saved_path)
rename_files()
</code>```

I'm using PyCharm version 2019.3

答:
you are accessing file_list before calling rename_files() so, it throws the error. Try to call the method before accessing the file_list.

```<code>rename_files()
for file_name in file_list:
    print("Old Name - "+file_name)
    print("New Name - "+file_name.translate(None, "0123456789"))
    os.rename(file_name, file_name.translate(None, "0123456789"))
</code>```

Or you can put this inside of the main body

```<code>file_list = os.listdir(r"C:\Users\test\PycharmProjects\proj1")
</code>```

Body:
I'm very new to Python programming.

And I'm trying to rename filenames inside a folder, so that new filenames will not have any number. E.g. if filename is 123abc.txt then new filename will be abc.txt. The code I've used is below but it is giving error

NameError: name 'file_list' is not defined.

Can someone please help, what mistake I've made?

import os
def rename_files():
    #Step-1 get file names from a folder
    file_list = os.listdir(r"C:\Users\test\PycharmProjects\proj1")
    print(file_list)
saved_path = os.getcwd()
print("Current working directory is " + saved_path)
        #Current working directory is C:\Users\test\PycharmProjects\proj1
os.chdir(r"C:\Users\test\PycharmProjects\proj1")
    #Step-2 for each filename, rename filename
for file_name in file_list:
    print("Old Name - "+file_name)
    print("New Name - "+file_name.translate(None, "0123456789"))
    os.rename(file_name, file_name.translate(None, "0123456789"))
os.chdir(saved_path)
rename_files()

I'm using PyCharm version 2019.3

Body:
you are accessing file_list before calling rename_files() so, it throws the error. Try to call the method before accessing the file_list.

rename_files()
for file_name in file_list:
    print("Old Name - "+file_name)
    print("New Name - "+file_name.translate(None, "0123456789"))
    os.rename(file_name, file_name.translate(None, "0123456789"))

Or you can put this inside of the main body

file_list = os.listdir(r"C:\Users\test\PycharmProjects\proj1")


问:
How to get the Sum of Lowest values in 3 rows each added dynamically
The following code will get the lowest value entered in first 3 columns, it is running fine. But after adding the row (Add Row) i am unable to get the lowest value from next 3 columns. Also i want to get the sum of all 3 lowest values from as much columns as user will add. Your kind help is required in this regard.

$(document).ready(function() {
  var i = 1;
  $("#Add_BDSP").click(function() {
    $('#BDSP' + i).html("<input type='text' name='QuotedAmount1[" + i + "]' placeholder='Quoted Amount' class='form-control' /><input type='text' name='QuotedAmount2[" + i + "]'placeholder='Quoted Amount' class='form-control' /><input type='text' name='QuotedAmount3[" + i + "]' placeholder='Quoted Amount' class='form-control'/>	");

    $('#Tab_BDSP').append('

');
    i++;
  });
  $("#Delete_BDSP").click(function() {
    if (i > 1) {
      $("#BDSP" + (i - 1)).html('');
      i--;
    }
  });

});

var input = $('[name="QuotedAmount1[0]"],[name="QuotedAmount2[0]"],[name="QuotedAmount3[0]"]'),

  QuotedAmount1 = $('[name="QuotedAmount1[0]"]'),
  QuotedAmount2 = $('[name="QuotedAmount2[0]"]'),
  QuotedAmount3 = $('[name="QuotedAmount3[0]"]'),

  MulRes = $('[name="ServiceTotalCost"]');

input.change(function() {
  var Qoute1 = (isNaN(parseInt(QuotedAmount1.val()))) ? 0 : parseInt(QuotedAmount1.val());
  var Qoute2 = (isNaN(parseInt(QuotedAmount2.val()))) ? 0 : parseInt(QuotedAmount2.val());
  var Qoute3 = (isNaN(parseInt(QuotedAmount3.val()))) ? 0 : parseInt(QuotedAmount3.val());

  MulRes.val(Math.min(Qoute1, Qoute2, Qoute3));

});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-group form-float">
  <table class="table table-bordered table-hover" id="Tab_BDSP">
    <thead>
      <tr>
        <td>Amount</td>

      </tr>
    </thead>
    <tbody>
      <tr id='BDSP0'>

        <td>
          <input type="text" name='QuotedAmount1[0]' placeholder='Quoted Amount' class="form-control" required />
          <input type="text" name='QuotedAmount2[0]' placeholder='Quoted Amount' class="form-control" required />
          <input type="text" name='QuotedAmount3[0]' placeholder='Quoted Amount' class="form-control" required />
        </td>

      </tr>

      <tr id='BDSP1'></tr>
    </tbody>
  </table>
</div>
Add RowDelete Row
</div>

<div class="col-md-4">

  <div class="input-group form-group">
    <span class="input-group-addon">
                                                    <i class="material-icons">business_center</i>
                                                </span>
    <div class="form-line">
      <input type="number" class="form-control" name="ServiceTotalCost" id="ServiceTotalCost" required>
    </div>
  </div>
</div></code>```

答:
But after adding the row (Add Row) i am unable to get the lowest value
  from next 3 columns

Your main problem is:

```<code>QuotedAmount1 = $('[name="QuotedAmount1[0]"]'),
QuotedAmount2 = $('[name="QuotedAmount2[0]"]'),
QuotedAmount3 = $('[name="QuotedAmount3[0]"]'),
</code>```

Because you just select QuotedAmount1[0] to QuotedAmount3[0], after you append row new input has QuotedAmount1[1] .. , also you used change and for new row you need to use change with document selector, to get live change. And you should move your variable inside of change event. Important things is, you should select your input without name, here is working snippet:

$(document).ready(function() {
  var i = 1;
  $("#Add_BDSP").click(function() {
    $('#BDSP' + i).html("<input type='text' name='QuotedAmount1[" + i + "]' placeholder='Quoted Amount' class='form-control' /><input type='text' name='QuotedAmount2[" + i + "]'placeholder='Quoted Amount' class='form-control' /><input type='text' name='QuotedAmount3[" + i + "]' placeholder='Quoted Amount' class='form-control'/>	");

    $('#Tab_BDSP').append('

');
    i++;
  });
  $("#Delete_BDSP").click(function() {
    if (i > 1) {
      $("#BDSP" + (i - 1)).html('');
      i--;
    }
  });

});

$(document).on('change', '#Tab_BDSP tbody tr td input[type="text"]', function() {
  let result = 0;
  var MulRes = $('input#ServiceTotalCost');

  var QuotedAmount1 = $(this).parent().find('input[type="text"]').eq(0),
    QuotedAmount2 = $(this).parent().find('input[type="text"]').eq(1),
    QuotedAmount3 = $(this).parent().find('input[type="text"]').eq(2);

  var Qoute1 = (isNaN(parseInt(QuotedAmount1.val()))) ? 0 : parseInt(QuotedAmount1.val()),
    Qoute2 = (isNaN(parseInt(QuotedAmount2.val()))) ? 0 : parseInt(QuotedAmount2.val()),
    Qoute3 = (isNaN(parseInt(QuotedAmount3.val()))) ? 0 : parseInt(QuotedAmount3.val());

  var min = Math.min(Qoute1, Qoute2, Qoute3);
  $(this).parent().attr('data-lowest', min)

  $('#Tab_BDSP tbody tr td').each(function() {
    result += +$(this).attr('data-lowest')
  });

  MulRes.val(result)
});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>Thank you for kind response,
the code is running perfect,
but the issue is if i change the value in additional rows,
it adds the lowest into the sum,
e.g. 1st row have 300000 400000 500000 and second row have 600000 700000 800000 The total sum will be 900000 which is perfect. but if i change the value from 600000 to 200000 it should shows 700000 but it gives value of 1100000. Your kind help is needed to rectify this issue in the given code. – ADIL I.T 8 mins ago</code>```

        Amount

          <input type="text" name='QuotedAmount1[0]' placeholder='Quoted Amount' class="form-control" required />
          <input type="text" name='QuotedAmount2[0]' placeholder='Quoted Amount' class="form-control" required />
          <input type="text" name='QuotedAmount3[0]' placeholder='Quoted Amount' class="form-control" required />

Add RowDelete Row

                                                    business_center

      <input type="number" class="form-control" name="ServiceTotalCost" id="ServiceTotalCost" required>

```

Also i want to get the sum of all 3 lowest values from as much columns
  as user will add

For get sum you need to get min and also old lowest value

Body:
The following code will get the lowest value entered in first 3 columns, it is running fine. But after adding the row (Add Row) i am unable to get the lowest value from next 3 columns. Also i want to get the sum of all 3 lowest values from as much columns as user will add. Your kind help is required in this regard.

$(document).ready(function() {
  var i = 1;
  $("#Add_BDSP").click(function() {
    $('#BDSP' + i).html("<input type='text' name='QuotedAmount1[" + i + "]' placeholder='Quoted Amount' class='form-control' /><input type='text' name='QuotedAmount2[" + i + "]'placeholder='Quoted Amount' class='form-control' /><input type='text' name='QuotedAmount3[" + i + "]' placeholder='Quoted Amount' class='form-control'/>	");

    $('#Tab_BDSP').append('

');
    i++;
  });
  $("#Delete_BDSP").click(function() {
    if (i > 1) {
      $("#BDSP" + (i - 1)).html('');
      i--;
    }
  });

});

var input = $('[name="QuotedAmount1[0]"],[name="QuotedAmount2[0]"],[name="QuotedAmount3[0]"]'),

  QuotedAmount1 = $('[name="QuotedAmount1[0]"]'),
  QuotedAmount2 = $('[name="QuotedAmount2[0]"]'),
  QuotedAmount3 = $('[name="QuotedAmount3[0]"]'),

  MulRes = $('[name="ServiceTotalCost"]');

input.change(function() {
  var Qoute1 = (isNaN(parseInt(QuotedAmount1.val()))) ? 0 : parseInt(QuotedAmount1.val());
  var Qoute2 = (isNaN(parseInt(QuotedAmount2.val()))) ? 0 : parseInt(QuotedAmount2.val());
  var Qoute3 = (isNaN(parseInt(QuotedAmount3.val()))) ? 0 : parseInt(QuotedAmount3.val());

  MulRes.val(Math.min(Qoute1, Qoute2, Qoute3));

});

        Amount

          <input type="text" name='QuotedAmount1[0]' placeholder='Quoted Amount' class="form-control" required />
          <input type="text" name='QuotedAmount2[0]' placeholder='Quoted Amount' class="form-control" required />
          <input type="text" name='QuotedAmount3[0]' placeholder='Quoted Amount' class="form-control" required />

Add RowDelete Row

                                                    business_center

      <input type="number" class="form-control" name="ServiceTotalCost" id="ServiceTotalCost" required>

Body:
But after adding the row (Add Row) i am unable to get the lowest value
  from next 3 columns

Your main problem is:

QuotedAmount1 = $('[name="QuotedAmount1[0]"]'),
QuotedAmount2 = $('[name="QuotedAmount2[0]"]'),
QuotedAmount3 = $('[name="QuotedAmount3[0]"]'),

Because you just select QuotedAmount1[0] to QuotedAmount3[0], after you append row new input has QuotedAmount1[1] .. , also you used change and for new row you need to use change with document selector, to get live change. And you should move your variable inside of change event. Important things is, you should select your input without name, here is working snippet:

$(document).ready(function() {
  var i = 1;
  $("#Add_BDSP").click(function() {
    $('#BDSP' + i).html("<td><input type='text' name='QuotedAmount1[" + i + "]' placeholder='Quoted Amount' class='form-control' /><input type='text' name='QuotedAmount2[" + i + "]'placeholder='Quoted Amount' class='form-control' /><input type='text' name='QuotedAmount3[" + i + "]' placeholder='Quoted Amount' class='form-control'/></td>");

    $('#Tab_BDSP').append('<tr id="BDSP' + (i + 1) + '"></tr>');
    i++;
  });
  $("#Delete_BDSP").click(function() {
    if (i > 1) {
      $("#BDSP" + (i - 1)).html('');
      i--;
    }
  });

});

$(document).on('change', '#Tab_BDSP tbody tr td input[type="text"]', function() {
  let result = 0;
  var MulRes = $('input#ServiceTotalCost');

  var QuotedAmount1 = $(this).parent().find('input[type="text"]').eq(0),
    QuotedAmount2 = $(this).parent().find('input[type="text"]').eq(1),
    QuotedAmount3 = $(this).parent().find('input[type="text"]').eq(2);

  var Qoute1 = (isNaN(parseInt(QuotedAmount1.val()))) ? 0 : parseInt(QuotedAmount1.val()),
    Qoute2 = (isNaN(parseInt(QuotedAmount2.val()))) ? 0 : parseInt(QuotedAmount2.val()),
    Qoute3 = (isNaN(parseInt(QuotedAmount3.val()))) ? 0 : parseInt(QuotedAmount3.val());

  var min = Math.min(Qoute1, Qoute2, Qoute3);
  $(this).parent().attr('data-lowest', min)

  $('#Tab_BDSP tbody tr td').each(function() {
    result += +$(this).attr('data-lowest')
  });

  MulRes.val(result)
});

Thank you for kind response,
the code is running perfect,
but the issue is if i change the value in additional rows,
it adds the lowest into the sum,
e.g. 1st row have 300000 400000 500000 and second row have 600000 700000 800000 The total sum will be 900000 which is perfect. but if i change the value from 600000 to 200000 it should shows 700000 but it gives value of 1100000. Your kind help is needed to rectify this issue in the given code. – ADIL I.T 8 mins ago

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-group form-float">
  <table class="table table-bordered table-hover" id="Tab_BDSP">
    <thead>
      <tr>
        <td>Amount</td>

      </tr>
    </thead>
    <tbody>
      <tr id='BDSP0'>

        <td>
          <input type="text" name='QuotedAmount1[0]' placeholder='Quoted Amount' class="form-control" required />
          <input type="text" name='QuotedAmount2[0]' placeholder='Quoted Amount' class="form-control" required />
          <input type="text" name='QuotedAmount3[0]' placeholder='Quoted Amount' class="form-control" required />
        </td>

      </tr>

      <tr id='BDSP1'></tr>
    </tbody>
  </table>
</div>
<a id="Add_BDSP" class="btn btn-default pull-left">Add Row</a><a id='Delete_BDSP' class="pull-right btn btn-default">Delete Row</a>
</div>

<div class="col-md-4">

  <div class="input-group form-group">
    <span class="input-group-addon">
                                                    <i class="material-icons">business_center</i>
                                                </span>
    <div class="form-line">
      <input type="number" class="form-control" name="ServiceTotalCost" id="ServiceTotalCost" required>
    </div>
  </div>
</div>

Also i want to get the sum of all 3 lowest values from as much columns
  as user will add

For get sum you need to get min and also old lowest value


问:
Create table - Mysql
I'm looking for a little help with this table.  First:  The table isn't being accepted by mysql. I'm getting a 150 error, which doesn't tell me much.  Second, I'm very certain that I'm not using the best data types & way to go about things.... please give me a little input!  </p>

```<code>CREATE  TABLE IF NOT EXISTS `axis`.`Employee` (
`idEmployee` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
`idAccount` INT(10) UNSIGNED NOT NULL ,
`user` VARCHAR(45) NULL DEFAULT NULL ,
`pass` VARCHAR(45) NULL DEFAULT NULL ,
`firstName` VARCHAR(45) NULL DEFAULT NULL ,
`lastName` VARCHAR(45) NULL DEFAULT NULL ,
`middleName` VARCHAR(45) NULL DEFAULT NULL ,
`idGrp` INT(10) UNSIGNED NULL DEFAULT NULL ,
`idCompany` INT(10) UNSIGNED NULL DEFAULT NULL ,
`idLocation` INT(10) UNSIGNED NULL DEFAULT NULL ,
`idUnit` INT(10) UNSIGNED NULL DEFAULT NULL ,
`idCrew` INT(10) UNSIGNED NULL DEFAULT NULL ,
`idPosition` INT(10) UNSIGNED NULL DEFAULT NULL ,
`officeLoc` VARCHAR(45) NULL DEFAULT NULL ,
`wPhone` VARCHAR(12) NULL DEFAULT NULL ,
`wCell` VARCHAR(12) NULL DEFAULT NULL ,
`wFax` VARCHAR(12) NULL DEFAULT NULL ,
`wEmail` VARCHAR(45) NULL DEFAULT NULL ,
`radio` VARCHAR(12) NULL DEFAULT NULL ,
`hPhone` VARCHAR(12) NULL DEFAULT NULL ,
`hCell` VARCHAR(12) NULL DEFAULT NULL ,
`hEmail` VARCHAR(45) NULL DEFAULT NULL ,
`addrOne` VARCHAR(45) NULL DEFAULT NULL ,
`addrTwo` VARCHAR(45) NULL DEFAULT NULL ,
`city` VARCHAR(45) NULL DEFAULT NULL ,
`state` VARCHAR(45) NULL DEFAULT NULL ,
`zip` VARCHAR(10) NULL DEFAULT NULL ,
`emergContact` VARCHAR(45) NULL DEFAULT NULL ,
`emergPhone` VARCHAR(12) NULL DEFAULT NULL ,
`gender` ENUM('male','female') NULL DEFAULT NULL ,
`birthDate` DATE NULL DEFAULT NULL ,
`ssn` VARCHAR(5) NULL DEFAULT NULL ,
`hireDate` DATE NULL DEFAULT NULL ,
`sepDate` DATE NULL DEFAULT NULL ,
`comment` VARCHAR(255) NULL DEFAULT NULL ,
`photo` MEDIUMBLOB NULL DEFAULT NULL ,
`isActive` BIT(1) NOT NULL DEFAULT 1 ,
`allowLogin` BIT(1) NOT NULL DEFAULT 0 ,
`trackTravel` BIT(1) NOT NULL DEFAULT 1 ,
`trackTimesheet` BIT(1) NOT NULL DEFAULT 1 ,
`defFltArr` VARCHAR(10) NULL DEFAULT NULL ,
`defFltDep` VARCHAR(10) NULL DEFAULT NULL ,
`defDayTimeStart` TIME NOT NULL DEFAULT '06:00:00' ,
`defHoursPerDay` DECIMAL(4,2) NOT NULL DEFAULT '11.50' ,
`userType` ENUM('root','admin','view','acl','report','employee') NOT NULL DEFAULT 'employee',
`created` DATETIME NOT NULL ,
`modified` TIMESTAMP NOT NULL ,
`modifiedBy` INT(10) UNSIGNED NULL DEFAULT NULL ,
PRIMARY KEY (`idEmployee`, `idAccount`, `idGrp`, `idCompany`, `idLocation`, `idUnit`, `idCrew`, `idPosition`, `modifiedBy`) ,
UNIQUE INDEX `UNIQUE` (`idEmployee` ASC) ,
INDEX `fk_Employee_Grp` (`idGrp` ASC) ,
INDEX `fk_Employee_Company` (`idCompany` ASC) ,
INDEX `fk_Employee_Unit` (`idUnit` ASC) ,
INDEX `fk_Employee_Location` (`idLocation` ASC) ,
INDEX `fk_Employee_Crew` (`idCrew` ASC) ,
INDEX `fk_Employee_Position` (`idPosition` ASC) ,
INDEX `fk_Employee_Employee` (`modifiedBy` ASC) ,
CONSTRAINT `fk_Employee_Grp`
FOREIGN KEY (`idGrp` )
REFERENCES `axis`.`Grp` (`idGrp` )
ON DELETE SET NULL
ON UPDATE CASCADE,
CONSTRAINT `fk_Employee_Company`
FOREIGN KEY (`idCompany` )
REFERENCES `axis`.`Company` (`idCompany` )
ON DELETE SET NULL
ON UPDATE CASCADE,
CONSTRAINT `fk_Employee_Unit`
FOREIGN KEY (`idUnit` )
REFERENCES `axis`.`Unit` (`idUnit` )
ON DELETE SET NULL
ON UPDATE CASCADE,
CONSTRAINT `fk_Employee_Location`
FOREIGN KEY (`idLocation` )
REFERENCES `axis`.`Location` (`idLocation` )
ON DELETE SET NULL
ON UPDATE CASCADE,
CONSTRAINT `fk_Employee_Crew`
FOREIGN KEY (`idCrew` )
REFERENCES `axis`.`Crew` (`idCrew` )
ON DELETE SET NULL
ON UPDATE CASCADE,
CONSTRAINT `fk_Employee_Position`
FOREIGN KEY (`idPosition` )
REFERENCES `axis`.`Position` (`idPosition` )
ON DELETE SET NULL
ON UPDATE CASCADE,
CONSTRAINT `fk_Employee_Employee`
FOREIGN KEY (`modifiedBy` )
REFERENCES `axis`.`Employee` (`idEmployee` )
ON DELETE SET NULL
ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci
</code>```

答: Uhm, I may be very wrong, but are you allowed to have more than one Primary Key? I thought the whole purpose was that it was indeed a Primary (Unique) Key.</p>

ContentLicense: CC BY-SA 3.0

Title: Create table - Mysql

Body:
I'm looking for a little help with this table.  First:  The table isn't being accepted by mysql. I'm getting a 150 error, which doesn't tell me much.  Second, I'm very certain that I'm not using the best data types & way to go about things.... please give me a little input!

CREATE  TABLE IF NOT EXISTS `axis`.`Employee` (
`idEmployee` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
`idAccount` INT(10) UNSIGNED NOT NULL ,
`user` VARCHAR(45) NULL DEFAULT NULL ,
`pass` VARCHAR(45) NULL DEFAULT NULL ,
`firstName` VARCHAR(45) NULL DEFAULT NULL ,
`lastName` VARCHAR(45) NULL DEFAULT NULL ,
`middleName` VARCHAR(45) NULL DEFAULT NULL ,
`idGrp` INT(10) UNSIGNED NULL DEFAULT NULL ,
`idCompany` INT(10) UNSIGNED NULL DEFAULT NULL ,
`idLocation` INT(10) UNSIGNED NULL DEFAULT NULL ,
`idUnit` INT(10) UNSIGNED NULL DEFAULT NULL ,
`idCrew` INT(10) UNSIGNED NULL DEFAULT NULL ,
`idPosition` INT(10) UNSIGNED NULL DEFAULT NULL ,
`officeLoc` VARCHAR(45) NULL DEFAULT NULL ,
`wPhone` VARCHAR(12) NULL DEFAULT NULL ,
`wCell` VARCHAR(12) NULL DEFAULT NULL ,
`wFax` VARCHAR(12) NULL DEFAULT NULL ,
`wEmail` VARCHAR(45) NULL DEFAULT NULL ,
`radio` VARCHAR(12) NULL DEFAULT NULL ,
`hPhone` VARCHAR(12) NULL DEFAULT NULL ,
`hCell` VARCHAR(12) NULL DEFAULT NULL ,
`hEmail` VARCHAR(45) NULL DEFAULT NULL ,
`addrOne` VARCHAR(45) NULL DEFAULT NULL ,
`addrTwo` VARCHAR(45) NULL DEFAULT NULL ,
`city` VARCHAR(45) NULL DEFAULT NULL ,
`state` VARCHAR(45) NULL DEFAULT NULL ,
`zip` VARCHAR(10) NULL DEFAULT NULL ,
`emergContact` VARCHAR(45) NULL DEFAULT NULL ,
`emergPhone` VARCHAR(12) NULL DEFAULT NULL ,
`gender` ENUM('male','female') NULL DEFAULT NULL ,
`birthDate` DATE NULL DEFAULT NULL ,
`ssn` VARCHAR(5) NULL DEFAULT NULL ,
`hireDate` DATE NULL DEFAULT NULL ,
`sepDate` DATE NULL DEFAULT NULL ,
`comment` VARCHAR(255) NULL DEFAULT NULL ,
`photo` MEDIUMBLOB NULL DEFAULT NULL ,
`isActive` BIT(1) NOT NULL DEFAULT 1 ,
`allowLogin` BIT(1) NOT NULL DEFAULT 0 ,
`trackTravel` BIT(1) NOT NULL DEFAULT 1 ,
`trackTimesheet` BIT(1) NOT NULL DEFAULT 1 ,
`defFltArr` VARCHAR(10) NULL DEFAULT NULL ,
`defFltDep` VARCHAR(10) NULL DEFAULT NULL ,
`defDayTimeStart` TIME NOT NULL DEFAULT '06:00:00' ,
`defHoursPerDay` DECIMAL(4,2) NOT NULL DEFAULT '11.50' ,
`userType` ENUM('root','admin','view','acl','report','employee') NOT NULL DEFAULT 'employee',
`created` DATETIME NOT NULL ,
`modified` TIMESTAMP NOT NULL ,
`modifiedBy` INT(10) UNSIGNED NULL DEFAULT NULL ,
PRIMARY KEY (`idEmployee`, `idAccount`, `idGrp`, `idCompany`, `idLocation`, `idUnit`, `idCrew`, `idPosition`, `modifiedBy`) ,
UNIQUE INDEX `UNIQUE` (`idEmployee` ASC) ,
INDEX `fk_Employee_Grp` (`idGrp` ASC) ,
INDEX `fk_Employee_Company` (`idCompany` ASC) ,
INDEX `fk_Employee_Unit` (`idUnit` ASC) ,
INDEX `fk_Employee_Location` (`idLocation` ASC) ,
INDEX `fk_Employee_Crew` (`idCrew` ASC) ,
INDEX `fk_Employee_Position` (`idPosition` ASC) ,
INDEX `fk_Employee_Employee` (`modifiedBy` ASC) ,
CONSTRAINT `fk_Employee_Grp`
FOREIGN KEY (`idGrp` )
REFERENCES `axis`.`Grp` (`idGrp` )
ON DELETE SET NULL
ON UPDATE CASCADE,
CONSTRAINT `fk_Employee_Company`
FOREIGN KEY (`idCompany` )
REFERENCES `axis`.`Company` (`idCompany` )
ON DELETE SET NULL
ON UPDATE CASCADE,
CONSTRAINT `fk_Employee_Unit`
FOREIGN KEY (`idUnit` )
REFERENCES `axis`.`Unit` (`idUnit` )
ON DELETE SET NULL
ON UPDATE CASCADE,
CONSTRAINT `fk_Employee_Location`
FOREIGN KEY (`idLocation` )
REFERENCES `axis`.`Location` (`idLocation` )
ON DELETE SET NULL
ON UPDATE CASCADE,
CONSTRAINT `fk_Employee_Crew`
FOREIGN KEY (`idCrew` )
REFERENCES `axis`.`Crew` (`idCrew` )
ON DELETE SET NULL
ON UPDATE CASCADE,
CONSTRAINT `fk_Employee_Position`
FOREIGN KEY (`idPosition` )
REFERENCES `axis`.`Position` (`idPosition` )
ON DELETE SET NULL
ON UPDATE CASCADE,
CONSTRAINT `fk_Employee_Employee`
FOREIGN KEY (`modifiedBy` )
REFERENCES `axis`.`Employee` (`idEmployee` )
ON DELETE SET NULL
ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci


问:
ExpressionChangedAfterItHasBeenCheckedError after updating to Angular 9 on changing parent property from the child when Ivy is enabled
I recently updated my Angular project to version 9. I was using a service to update the header of the main menu and it was working successfully but now generates this error:

core.js:5828 ERROR Error: ExpressionChangedAfterItHasBeenCheckedError:
  Expression has changed after it was checked. Previous value:
  'main title'. Current value: 'new title'.

This error occurs every time the title changes.

This is part of my code:

My routing:

app-routing.module.ts:

```<code>const routes: Routes = [
  {
    path: '',
    component: MainComponent,
    canActivate: [AuthGuard],
    canActivateChild: [AuthGuard],

    children: [
      {
        path: '',
        component: DashboardComponent
      },
      {
        path: 'warehouse',
        loadChildren: () =>
          import('./systems/warehouse/warehouse.module').then(
            m => m.WarehouseModule
          )
      },
      {
        path: 'commerce',
        loadChildren: () =>
          import('./systems/commerce/commerce.module').then(
            m => m.CommerceModule
          )
      },
      {
...
</code>```

The main component:

main.component.ts:

```<code>  pageTitle: string;

  ngOnInit() {
    this.mainService.pageTitle$.subscribe((title: string) => {
      this.pageTitle = title;
    });
...
</code>```

The service I'm using to change the title:
main.service.ts:

```<code>  public setTitle(title: string) {
    this.pageTitle$.emit(title);
  }
</code>```

And finally one of my clients inside warehouse module that changes the title:

main.service.ts:

```<code>this.mainService.setTitle('new title');
</code>```

UPDATE:

The problem happens just when Ivy is enabled and in development mode. There is no error with "enableIvy": false or when production.

答:
I was calling 'setTitle' function in ngOnInit. Calling it from the constructor fixed the problem.

This makes an error when not in production mode:

```<code>ngOnInit() {
    this.mainService.setTitle('My title');
}
</code>```

And this fixes the problem:

```<code>constructor(
  private mainService: MainService
) {
  this.mainService.setTitle('My title');
}
</code>```

Body:
I recently updated my Angular project to version 9. I was using a service to update the header of the main menu and it was working successfully but now generates this error:

core.js:5828 ERROR Error: ExpressionChangedAfterItHasBeenCheckedError:
  Expression has changed after it was checked. Previous value:
  'main title'. Current value: 'new title'.

This error occurs every time the title changes.

This is part of my code:

My routing:

app-routing.module.ts:

const routes: Routes = [
  {
    path: '',
    component: MainComponent,
    canActivate: [AuthGuard],
    canActivateChild: [AuthGuard],

    children: [
      {
        path: '',
        component: DashboardComponent
      },
      {
        path: 'warehouse',
        loadChildren: () =>
          import('./systems/warehouse/warehouse.module').then(
            m => m.WarehouseModule
          )
      },
      {
        path: 'commerce',
        loadChildren: () =>
          import('./systems/commerce/commerce.module').then(
            m => m.CommerceModule
          )
      },
      {
...

The main component:

main.component.ts:

  pageTitle: string;

  ngOnInit() {
    this.mainService.pageTitle$.subscribe((title: string) => {
      this.pageTitle = title;
    });
...

The service I'm using to change the title:
main.service.ts:

  public setTitle(title: string) {
    this.pageTitle$.emit(title);
  }

And finally one of my clients inside warehouse module that changes the title:

main.service.ts:

this.mainService.setTitle('new title');

UPDATE:

The problem happens just when Ivy is enabled and in development mode. There is no error with "enableIvy": false or when production.

Body:
I was calling 'setTitle' function in ngOnInit. Calling it from the constructor fixed the problem.

This makes an error when not in production mode:

ngOnInit() {
    this.mainService.setTitle('My title');
}

And this fixes the problem:

constructor(
  private mainService: MainService
) {
  this.mainService.setTitle('My title');
}


问:
How to find out the correct query in laravel?
I have a query in my controller.

```<code>$results = DB::table('zaiko')
               ->where('soukobango',$souko_bango_for_joining)
               ->join('syouhin1','zaiko.syouhinbango','=','syouhin1.bango')
               ->where('syouhin1.isphoto','is distinct from','1')
               ->select(DB::raw("syouhin1.bango,
                  syouhin1.kokyakusyouhinbango,
                  syouhin1.jouhou,
                  syouhin1.tokuchou,
                  zaiko.tanabango,
                  SPLIT_PART(zaiko.datachar02, '|', 1) AS lot_no"))
</code>```

This is working ok. Now, I want to get some $special_result from $results. I want to match the existing result with two arrays and get that result.

```<code>$special_syouhin_bangos = [10,11];
$special_tana_bangos = ["MIKAKUTEI","TANA01"];

$special_syouhins = $results->wherein('syouhin1.bango',$special_syouhin_bangos)
                            ->wherein('zaiko.tanabango',$special_tana_bangos)->get();
</code>```

What I am getting is like below,

```<code>+--------------+-----------+
| syouhinbango | tanabango |
+--------------+-----------+
| 10           | MIKAKUTEI |
+--------------+-----------+
| 11           | MIKAKUTEI |
+--------------+-----------+
| 11           | TANA01    |
+--------------+-----------+
</code>```

What I want is like below,

```<code>+--------------+-----------+
| syouhinbango | tanabango |
+--------------+-----------+
| 10           | MIKAKUTEI |
+--------------+-----------+
| 11           | TANA01    |
+--------------+-----------+
</code>```

What I want is match the first element of $special_syouhin_bangos(10) with first element of $special_tana_bangos(MIKAKUTEI) and get one row of that. Then I want to match the second elements of both array and get another row as result. This way I want to get the $special_results. It is guaranteed that both $special_syouhin_bangos and $special_tana_bangos will have same number of elements.

I feel like I need to run a loop. But I still can't quite work it out.

答:
Replace

```<code>$special_syouhins = $results->wherein('syouhin1.bango',$special_syouhin_bangos)
                        ->wherein('zaiko.tanabango',$special_tana_bangos)->get();
</code>```

with

```<code>$special_syouhins = $results->wherein('syouhin1.bango',$special_syouhin_bangos)
                        ->wherein('zaiko.tanabango',$special_tana_bangos)->distinct()->get();
</code>```

Body:
I have a query in my controller.

$results = DB::table('zaiko')
               ->where('soukobango',$souko_bango_for_joining)
               ->join('syouhin1','zaiko.syouhinbango','=','syouhin1.bango')
               ->where('syouhin1.isphoto','is distinct from','1')
               ->select(DB::raw("syouhin1.bango,
                  syouhin1.kokyakusyouhinbango,
                  syouhin1.jouhou,
                  syouhin1.tokuchou,
                  zaiko.tanabango,
                  SPLIT_PART(zaiko.datachar02, '|', 1) AS lot_no"))

This is working ok. Now, I want to get some $special_result from $results. I want to match the existing result with two arrays and get that result.

$special_syouhin_bangos = [10,11];
$special_tana_bangos = ["MIKAKUTEI","TANA01"];

$special_syouhins = $results->wherein('syouhin1.bango',$special_syouhin_bangos)
                            ->wherein('zaiko.tanabango',$special_tana_bangos)->get();

What I am getting is like below,

+--------------+-----------+
| syouhinbango | tanabango |
+--------------+-----------+
| 10           | MIKAKUTEI |
+--------------+-----------+
| 11           | MIKAKUTEI |
+--------------+-----------+
| 11           | TANA01    |
+--------------+-----------+

What I want is like below,

+--------------+-----------+
| syouhinbango | tanabango |
+--------------+-----------+
| 10           | MIKAKUTEI |
+--------------+-----------+
| 11           | TANA01    |
+--------------+-----------+

What I want is match the first element of $special_syouhin_bangos(10) with first element of $special_tana_bangos(MIKAKUTEI) and get one row of that. Then I want to match the second elements of both array and get another row as result. This way I want to get the $special_results. It is guaranteed that both $special_syouhin_bangos and $special_tana_bangos will have same number of elements.

I feel like I need to run a loop. But I still can't quite work it out.

Body:
Replace

$special_syouhins = $results->wherein('syouhin1.bango',$special_syouhin_bangos)
                        ->wherein('zaiko.tanabango',$special_tana_bangos)->get();

with

$special_syouhins = $results->wherein('syouhin1.bango',$special_syouhin_bangos)
                        ->wherein('zaiko.tanabango',$special_tana_bangos)->distinct()->get();


问:
Generating report in Node JS
I want to generate a report(i.e pdf or any format that can be print) from the data in system. Its like i need to generate weekly report. Format of report will be the same but data will be change with time. Is there any way to perform this task in Node JS ? I m using Mongo DB. And React JS in front end. Thank you so much.

答: If you want to generate the HTML based pdf then html-pdf lib. It is the best lib to convert your HTML to pdf. I have already use the lib in my many projects to generate the pdf reports.</p>

Title: Generating report in Node JS


问:
What did I install (NPM)?
I was trying to install forever with the package manager NPM.

I ran the following code:

```<code>sudo npm install foever -g
</code>```

I misspelled "forever" obviously, but it did something. It said:

foever@0.0.1-security
  updated 1 package in 0.163s

I can't find any info on foever. Does anyone have any idea what this did to my system?

答:
run

```<code>npm uninstall <module_name>
</code>```

and you can get rid of it since its of no use.

Title: What did I install (NPM)?

Body:
I was trying to install forever with the package manager NPM.

I ran the following code:

sudo npm install foever -g

I misspelled "forever" obviously, but it did something. It said:

foever@0.0.1-security
  updated 1 package in 0.163s

I can't find any info on foever. Does anyone have any idea what this did to my system?

Body:
run

npm uninstall <module_name>

and you can get rid of it since its of no use.


问:
How to execute python program and save output in different file names automatically
I have a Python program which processes images and save the resulting output to a file. I am receiving the input and output file names via console using input(). But I want to save the output automatically with the file name as something like "input_file_name_out". Note the string "_out" attached to the input file name

This will help me get user input only for Input file names thereby saving little time for the user since he doesn't need to think everytime what should be the output file name

Sample code snippet

```<code>if __name__ == "__main__":

    in_file = input()
    out_file = input()

    processed = process_image(in_file,out_file)
</code>```

Expected code snippet

```<code>if __name__ == "__main__":

    in_file = input()
    # out_file = input() ------Not getting the file name from user thereby supplying only one argument to the below function

        processed = process_image(in_file)

# And within the function
def process_image(img):
    .
    .
    .
    out_file = img+"_out.jpg" ##### What should come here to achieve my requirement ########
    cv2.imwrite(out_file,processed_image)
</code>```

答:
you could make use of the Path class from the pathlib module:

```<code>from pathlib import Path

in_file = Path(input())
insert = '_out'

out_file = in_file.parent / (in_file.stem + insert + in_file.suffix)
</code>```

Example:

```<code>in_file = Path('D:/folder/test.jpg')
insert = '_out'
out_file = in_file.parent / (in_file.stem + insert + in_file.suffix)

print(out_file)
D:\folder\test_out.jpg
</code>```

Body:
I have a Python program which processes images and save the resulting output to a file. I am receiving the input and output file names via console using input(). But I want to save the output automatically with the file name as something like "input_file_name_out". Note the string "_out" attached to the input file name

This will help me get user input only for Input file names thereby saving little time for the user since he doesn't need to think everytime what should be the output file name

Sample code snippet

if __name__ == "__main__":

    in_file = input()
    out_file = input()

    processed = process_image(in_file,out_file)

Expected code snippet

if __name__ == "__main__":

    in_file = input()
    # out_file = input() ------Not getting the file name from user thereby supplying only one argument to the below function

        processed = process_image(in_file)

# And within the function
def process_image(img):
    .
    .
    .
    out_file = img+"_out.jpg" ##### What should come here to achieve my requirement ########
    cv2.imwrite(out_file,processed_image)

Body:
you could make use of the Path class from the pathlib module:

from pathlib import Path

in_file = Path(input())
insert = '_out'

out_file = in_file.parent / (in_file.stem + insert + in_file.suffix)

Example:

in_file = Path('D:/folder/test.jpg')
insert = '_out'
out_file = in_file.parent / (in_file.stem + insert + in_file.suffix)

print(out_file)
D:\folder\test_out.jpg


答:
If you have an integers table, you can generate all the days in your desired timespan and join those with the tallies of IPs for each day appearing in your table:

```<code>   SELECT timespan."day",
          COALESCE(num_uniq_ips, 0) AS num_uniq_ips,
          COALESCE(num_records, 0) AS num_records
     FROM (SELECT DATE_SUB(CURRENT_DATE, INTERVAL i DAY) AS "day"
             FROM integers
            WHERE i < 30) timespan
LEFT JOIN (SELECT DATE(created_date) AS "day",
                  COUNT(DISTINCT ip) AS num_uniq_ips,
                  COUNT(1) AS num_records
             FROM so6025149
         GROUP BY 1) tallies
          ON timespan."day" = tallies."day"
 ORDER BY timespan."day" ASC;
</code>```

Title: How do I create an array of data for 30 days from database table where some dates are not entered?

Body:
Let's say you have a simple table with:

ID  IP                  CREATED_DATE
-------------------------------------------------------
1   111.111.111.111     2011-03-28 14:12:31
2   111.111.111.111     2011-03-29 03:38:12
3   222.222.222.222     2011-04-02 12:04:45
4   111.111.111.111     2011-04-02 22:13:23
5   333.333.333.333     2011-04-03 05:53:15
6   222.222.222.222     2011-04-05 02:13:51
7   111.111.111.111     2011-04-07 11:45:34

I need to query the last 30 days and get a count of unique ips and total rows per day even if there are no entries for that day. So days that are not entered would obviously just be 0 as the array value for both unique and total rows.

Body:
If you have an integers table, you can generate all the days in your desired timespan and join those with the tallies of IPs for each day appearing in your table:

   SELECT timespan."day",
          COALESCE(num_uniq_ips, 0) AS num_uniq_ips,
          COALESCE(num_records, 0) AS num_records
     FROM (SELECT DATE_SUB(CURRENT_DATE, INTERVAL i DAY) AS "day"
             FROM integers
            WHERE i < 30) timespan
LEFT JOIN (SELECT DATE(created_date) AS "day",
                  COUNT(DISTINCT ip) AS num_uniq_ips,
                  COUNT(1) AS num_records
             FROM so6025149
         GROUP BY 1) tallies
          ON timespan."day" = tallies."day"
 ORDER BY timespan."day" ASC;


答:
Could you please try following.</p>

```<code>for row in df['Domains']:
    print(re.findall(r'Note=([^;]*)', row))
</code>```

Title: Extract word uptill certain symbol

Body:
Hi I have this uniprot gff data that looks like

+--------+--------+-------+------+------------------------------------------------------------------------------------------------------+
| Entry  | check  | start | end  |                                               Domains                                               |
+--------+--------+-------+------+------------------------------------------------------------------------------------------------------+
| O75581 | Repeat |    63 |  106 |  Note=LDL-receptor class B 1                                                                         |
| O75581 | Repeat |   150 |  193 |  Note=LDL-receptor class B 3                                                                         |
| O75581 | Domain |   282 |  324 |  Note=EGF-like 1                                                                                |
| O75581 | Domain |  1248 | 1286 |  Note=LDL-receptor class A 1;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00124 |
| O75581 | Domain |  1287 | 1323 |  Note=LDL-receptor class A 2;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00124 |
| O75581 | Domain |  1325 | 1361 |  Note=LDL-receptor class A 3;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00124 |
| P13688 | Domain |    35 |  142 |  Note=Ig-like V-type;Ontology_term=ECO:0000250;evidence=ECO:0000250|UniProtKB:P31997                 |
| P13688 | Domain |   145 |  232 |  Note=Ig-like C2-type 1;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00114      |
| P13688 | Domain |   237 |  317 |  Note=Ig-like C2-type 2;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00114      |
| P13688 | Domain |   323 |  413 |  Note=Ig-like C2-type 3;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00114      |
| P19022 | Domain |   160 |  267 |  Note=Cadherin 1;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00043             |
| P19022 | Domain |   268 |  382 |  Note=Cadherin 2;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00043             |
| P19022 | Domain |   383 |  497 |  Note=Cadherin 3;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00043             |
| Q13586 | Domain |   132 |  200 |  Note=SAM;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00184                    |
| P04629 | Repeat |    90 |  113 |  Note=LRR 1                                                                                |
| P04629 | Repeat |   116 |  137 |  Note=LRR 2                                                                                |
+--------+--------+-------+------+------------------------------------------------------------------------------------------------------+

I am trying to extract the domain names column df['Domains]. With the following code, I am close to getting the first 2 3 words of the domain name but doesn't work universally.

for row in df['Domains']:
    print(re.findall(r'Note=(\w*)(.?)(\w*)', row))

which gives something like this

[('LDL', '-', 'receptor')]
[('LDL', '-', 'receptor')]
[('EGF', '-', 'like')]
[('Ig', '-', 'like')]
[('Ig', '-', 'like')]`

So, I wish to change my approach and get everything starting after Note= and ends before ; or end of line. How may I get this?

Body:
Could you please try following.

for row in df['Domains']:
    print(re.findall(r'Note=([^;]*)', row))


问:
Creating a custom android UI
does anyone know how I would get started creating a custom android UI?
it wouldn't be an app. Once you install it, it would change the appearance of your UI until you uninstall it.

I've done some research but it doesn't seem to be possible/available yet??

If anyone could help or link me to a site on how to to get started that'd be awesome, thx!

I program using eclipse, btw.

This is basically what i want to do, but i want to design it myself http://www.intomobile.com/2011/02/09/sentio-ui-android-home-replacement-app/
How would I get started?

答:
I think you want to create a custom theme that can be selected by the user. There unfortunately is VERY little documentation around that. The most extensive writeup I've found is at http://www.android.net/forum/custom-android-themes/58323-tutorial-making-themes.html, and after reviewing it I wasn't really able to get too far myself.

A similar question was also asked at How to create and manage custom themes for whole Android system?. Let me know if you find something that works for you.

Title: Creating a custom android UI


答:
file_list was called at end by function rename_files(), but before that only your for loop was trying to access variable file_list. Below is update code. </p>

```<code>import os

#Step-1 get file names from a folder
file_list = os.listdir(r"C:\Users\test\PycharmProjects\proj1")
print(file_list)

saved_path = os.getcwd()
print("Current working directory is " + saved_path)
        #Current working directory is C:\Users\test\PycharmProjects\proj1
os.chdir(r"C:\Users\test\PycharmProjects\proj1")
    #Step-2 for each filename, rename filename
for file_name in file_list:
    print("Old Name - "+file_name)
    print("New Name - "+file_name.translate(None, "0123456789"))
    os.rename(file_name, file_name.translate(None, "0123456789"))
os.chdir(saved_path)

</code>```

Title: Python NameError: name 'file_list' is not defined while renaming filenames

Body:
I'm very new to Python programming.

And I'm trying to rename filenames inside a folder, so that new filenames will not have any number. E.g. if filename is 123abc.txt then new filename will be abc.txt. The code I've used is below but it is giving error

NameError: name 'file_list' is not defined.

Can someone please help, what mistake I've made?

import os
def rename_files():
    #Step-1 get file names from a folder
    file_list = os.listdir(r"C:\Users\test\PycharmProjects\proj1")
    print(file_list)
saved_path = os.getcwd()
print("Current working directory is " + saved_path)
        #Current working directory is C:\Users\test\PycharmProjects\proj1
os.chdir(r"C:\Users\test\PycharmProjects\proj1")
    #Step-2 for each filename, rename filename
for file_name in file_list:
    print("Old Name - "+file_name)
    print("New Name - "+file_name.translate(None, "0123456789"))
    os.rename(file_name, file_name.translate(None, "0123456789"))
os.chdir(saved_path)
rename_files()

I'm using PyCharm version 2019.3

Body:
file_list was called at end by function rename_files(), but before that only your for loop was trying to access variable file_list. Below is update code.

import os

#Step-1 get file names from a folder
file_list = os.listdir(r"C:\Users\test\PycharmProjects\proj1")
print(file_list)

saved_path = os.getcwd()
print("Current working directory is " + saved_path)
        #Current working directory is C:\Users\test\PycharmProjects\proj1
os.chdir(r"C:\Users\test\PycharmProjects\proj1")
    #Step-2 for each filename, rename filename
for file_name in file_list:
    print("Old Name - "+file_name)
    print("New Name - "+file_name.translate(None, "0123456789"))
    os.rename(file_name, file_name.translate(None, "0123456789"))
os.chdir(saved_path)


问:
How to call Db view file in repository pattern?
I am creating a view file in SQL Server as shown in the image below.

and I created a model to get results from this view:

```<code>public class FactALLCousumption : BaseEntity, IAggregateRoot
{

    public double sumActiveImportTotal { get;  set; }
    public DateTime hour { get;  set; }
    public int fullDateAlternateKey { get;  set; }
}
</code>```

But I can't call this view in my repository. My repository code is bellow:

```<code>public class FactCousumptionRepository: GenericRepository<FactCousumption>, IFactCousumptionRepository
{
    public DbContext _dbContext;

    public FactCousumptionRepository(BaseDbContext context) : base(context)
    {
        _dbContext = context;
    }

    public async Task<FactALLCousumption> GetTotalAllCousumption()
    {

    }
}
</code>```

答:
In EF Core 2.2 or 2.1, you could use Query types.

According to the screenshot and the model to be used for the View you provided , I make a simple working demo like below , you could refer to and make the modification as per your demand:

1.Model

```<code> public class FactCousumption
{
    public int Id { get; set; }
    public double SumActiveImportTotal { get; set; }
    public int DateKeyId { get; set; }
    [ForeignKey("DateKeyId")]
    public Dim_Date Dim_Date { get; set; }
    public int TimeAltKeyId { get; set; }
    [ForeignKey("TimeAltKeyId")]
    public Dim_Time Dim_Time { get; set; }
    public int TariffKeyId { get; set; }
    [ForeignKey("TariffKeyId")]
    public Dim_Tariff Dim_Tariff { get; set; }
}

public class Dim_Date
{
    [Key]
    public int DateKey { get; set; }
    public int FullDateAlternateKey { get; set; }
    public DateTime Date { get; set; }
    public ICollection<FactCousumption> FactCousumptions { get; set; }
}

public class Dim_Time
{
    [Key]
    public int TimeAltKey { get; set; }
    public DateTime Hour { get; set; }
    public ICollection<FactCousumption> FactCousumptions { get; set; }
}
 public class Dim_Tariff
{
    [Key]
    public int TariffType { get; set; }
    public string TariffName { get; set; }

    public ICollection<FactCousumption> FactCousumptions { get; set; }
}
</code>```

2.Create SQL View

```<code>CREATE VIEW [dbo].[View1]
AS  SELECT SUM(FactCousumption.SumActiveImportTotal) AS consumption ,Dim_Time.HOUR,Dim_Date.FullDateAlternateKey,Dim_Tariff.TariffName
  FROM FactCousumption INNER JOIN
        Dim_Date ON FactCousumption.DateKeyId = Dim_Date.DateKey INNER JOIN
        Dim_Time ON FactCousumption.TimeAltKeyId=Dim_Time.TimeAltKey INNER JOIN
        Dim_Tariff ON FactCousumption.TariffKeyId=Dim_Tariff.TariffType
  GROUP BY Dim_Date.FullDateAlternateKey, Dim_Time.HOUR ,Dim_Tariff.TariffName
</code>```

3.The model that is used for the view , note : the property name in model should be consistent with those in the view

```<code>public class FactALLCousumption
{
    public double consumption { get; set; }
    public DateTime hour { get; set; }
    public int fullDateAlternateKey { get; set; }
}
</code>```

4.DbContext , create  a DbQuery property in my DbContext to consume the view results inside the Model and set up the View especially if you have different view name than your Class.

```<code> public DbQuery<FactALLCousumption> FactALLCousumption { get; set; }

 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Query<FactALLCousumption>().ToView("View1");
 }
</code>```

5.Finally you can easily get the results of the View like this.

```<code>public async Task<FactALLCousumption> GetTotalAllCousumption()
{
        var result = await _context.FactALLCousumption.FirstOrDefaultAsync();

        return result;
}
</code>```

Note: It's worth noting that DbQuery won't be/is not supported anymore in EF Core 3.0. See here

Body:
I am creating a view file in SQL Server as shown in the image below.

and I created a model to get results from this view:

public class FactALLCousumption : BaseEntity, IAggregateRoot
{

    public double sumActiveImportTotal { get;  set; }
    public DateTime hour { get;  set; }
    public int fullDateAlternateKey { get;  set; }
}

But I can't call this view in my repository. My repository code is bellow:

public class FactCousumptionRepository: GenericRepository<FactCousumption>, IFactCousumptionRepository
{
    public DbContext _dbContext;

    public FactCousumptionRepository(BaseDbContext context) : base(context)
    {
        _dbContext = context;
    }

    public async Task<FactALLCousumption> GetTotalAllCousumption()
    {

    }
}

Body:
In EF Core 2.2 or 2.1, you could use Query types.

According to the screenshot and the model to be used for the View you provided , I make a simple working demo like below , you could refer to and make the modification as per your demand:

1.Model

 public class FactCousumption
{
    public int Id { get; set; }
    public double SumActiveImportTotal { get; set; }
    public int DateKeyId { get; set; }
    [ForeignKey("DateKeyId")]
    public Dim_Date Dim_Date { get; set; }
    public int TimeAltKeyId { get; set; }
    [ForeignKey("TimeAltKeyId")]
    public Dim_Time Dim_Time { get; set; }
    public int TariffKeyId { get; set; }
    [ForeignKey("TariffKeyId")]
    public Dim_Tariff Dim_Tariff { get; set; }
}

public class Dim_Date
{
    [Key]
    public int DateKey { get; set; }
    public int FullDateAlternateKey { get; set; }
    public DateTime Date { get; set; }
    public ICollection<FactCousumption> FactCousumptions { get; set; }
}

public class Dim_Time
{
    [Key]
    public int TimeAltKey { get; set; }
    public DateTime Hour { get; set; }
    public ICollection<FactCousumption> FactCousumptions { get; set; }
}
 public class Dim_Tariff
{
    [Key]
    public int TariffType { get; set; }
    public string TariffName { get; set; }

    public ICollection<FactCousumption> FactCousumptions { get; set; }
}

2.Create SQL View

CREATE VIEW [dbo].[View1]
AS  SELECT SUM(FactCousumption.SumActiveImportTotal) AS consumption ,Dim_Time.HOUR,Dim_Date.FullDateAlternateKey,Dim_Tariff.TariffName
  FROM FactCousumption INNER JOIN
        Dim_Date ON FactCousumption.DateKeyId = Dim_Date.DateKey INNER JOIN
        Dim_Time ON FactCousumption.TimeAltKeyId=Dim_Time.TimeAltKey INNER JOIN
        Dim_Tariff ON FactCousumption.TariffKeyId=Dim_Tariff.TariffType
  GROUP BY Dim_Date.FullDateAlternateKey, Dim_Time.HOUR ,Dim_Tariff.TariffName

3.The model that is used for the view , note : the property name in model should be consistent with those in the view

public class FactALLCousumption
{
    public double consumption { get; set; }
    public DateTime hour { get; set; }
    public int fullDateAlternateKey { get; set; }
}

4.DbContext , create  a DbQuery property in my DbContext to consume the view results inside the Model and set up the View especially if you have different view name than your Class.

 public DbQuery<FactALLCousumption> FactALLCousumption { get; set; }

 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Query<FactALLCousumption>().ToView("View1");
 }

5.Finally you can easily get the results of the View like this.

public async Task<FactALLCousumption> GetTotalAllCousumption()
{
        var result = await _context.FactALLCousumption.FirstOrDefaultAsync();

        return result;
}

Note: It's worth noting that DbQuery won't be/is not supported anymore in EF Core 3.0. See here


问:
Two paths under the same package in bintray
I have successfully uploaded a library to bintray, which shows the version and the dependency correctly. But when I requested to link it to jcenter, I got this response:

Hi,

We can see that there are two paths under the same package, one used for the .aar/.jar/.apk and jar-sources.jar and *-javadoc.jar files on under:
  /com/androiddev/android-dev-core/1.0.0

and one for the .pom file:
  /com/androiddev/core/1.0.0

We can only approve one path for a single package.
  Please consolidate the two paths and let us know which path prefix you would like to include.

Thanks,
  JFrog Support

I can see the two paths under file section in bintray. Any idea how to solve this?

答:
If your lib and artifact have different name,  you will see there will be two folders in bintray's file section. Pom files and jar files will be in different folder. To avoid this, you should rename your artifact and your lib(module) as same.

I think that bintray project name can be different. It is optional. Artifact and module name equality will be enough. You will see your pom files and jar files in same folder after build your project.


问:
How to write a loop for automatic slideshow?
I want to add a loop to a slideshow but I'm new to jQuery and don't know how to do it. and here are the codes: </p>

```<code>$(function(){
    $("#slide_container").mouseout(function(){

        /*a loop here that change the images automatically when the mouse is not inside the div,
        get the index of the image and add to it like a for loop (i = 0; i < slides.length; i++)
        but I still don't know which var should I add and how mouseout works.*/

    });

    $("#slide_container").mouseover(function(){
        $('#nextBtn').on('click', function(){
            console.log('clicked');
            var currentImg = $(".active");
            var nextImg = currentImg.next();

            if(nextImg.length){
                currentImg.removeClass('active').css('z-index', -10);
                nextImg.addClass('active').css('z-index', 10);
            }

        });

        $('#prevBtn').on('click', function(){
            console.log('clicked');
            var currentImg = $(".active");
            var prevImg = currentImg.prev();
            if(prevImg.length){
                currentImg.removeClass('active').css('z-index', -10);
                prevImg.addClass('active').css('z-index', 10);
            }

        })
</code>```

答:
you can use setInterval. to execute a piece if code continuously over a inertial interval

you can trigger the click on the buttons to forward the slid

let s_interval = null;
const DELAY = 1000 //1s between each transition

$("#slide_container").mouseout(function(){
   const next_button = $('#nextBtn')
   s_interval = setInterval(()=> next_button.click(),DELAY)
});

$("#slide_container").mouseenter(function(){
   clearInterval(s_interval)
});
```

Body:
I want to add a loop to a slideshow but I'm new to jQuery and don't know how to do it. and here are the codes:

$(function(){
    $("#slide_container").mouseout(function(){

        /*a loop here that change the images automatically when the mouse is not inside the div,
        get the index of the image and add to it like a for loop (i = 0; i < slides.length; i++)
        but I still don't know which var should I add and how mouseout works.*/

    });

    $("#slide_container").mouseover(function(){
        $('#nextBtn').on('click', function(){
            console.log('clicked');
            var currentImg = $(".active");
            var nextImg = currentImg.next();

            if(nextImg.length){
                currentImg.removeClass('active').css('z-index', -10);
                nextImg.addClass('active').css('z-index', 10);
            }

        });

        $('#prevBtn').on('click', function(){
            console.log('clicked');
            var currentImg = $(".active");
            var prevImg = currentImg.prev();
            if(prevImg.length){
                currentImg.removeClass('active').css('z-index', -10);
                prevImg.addClass('active').css('z-index', 10);
            }

        })