Python/Django Filter with Datetime and extra options

I’m creating a filter in python/django. I want to make a datetime human-readable. You have multiple options: Plain Datetime (“04. Februar 2018, 18:18”)

(bools="False,False"), 

sentence Datetime (“am 04. Februar 2018 um 18:18”)

(bools="True,False"),  

onlydate Datetime (“04. Februar 2018”)

(bools="False,True"),  

sentence and onlyDate (“am 04. Februar 2018”)

(bools="True,True") 

Here’s my filter:

@register.filter def naturaldaytime(daytime, bools="False,False"):     if daytime is None:         return daytime      sentence = str2bool(bools.split(",")[0])     onlyDate = str2bool(bools.split(",")[1])      now = datetime.datetime.now()     difference = now.day - daytime.replace(tzinfo=None).day     loc = locale.setlocale(locale.LC_TIME, "de")      if onlyDate:         if difference == 0:             return daytime.strftime(settings.DATE_FORMAT_TODAY) if not sentence else daytime.strftime(settings.DATE_FORMAT_SENTENCE)         elif difference == 1:             return daytime.strftime(settings.DATE_FORMAT_YESTERDAY) if not sentence else daytime.strftime(settings.DATE_FORMAT_YESTERDAY)         elif now.isocalendar()[0] == daytime.isocalendar()[0]:             if now.isocalendar()[1] == daytime.isocalendar()[1]:                 return daytime.strftime(settings.DATE_FORMAT_THIS_WEEK) if not sentence else daytime.strftime(settings.DATE_FORMAT_THIS_WEEK_SENTENCE)             return daytime.strftime(settings.DATE_FORMAT_THIS_YEAR) if not sentence else daytime.strftime(settings.DATE_FORMAT_THIS_YEAR_SENTENCE)         return daytime.strftime(settings.DATE_FORMAT) if not sentence else daytime.strftime(settings.DATE_FORMAT_SENTENCE)     else:         pass         #so what...   def str2bool(v):     return v.lower() in ("yes", "true", "t", "1") 

and my settings vars:

TIME_FORMAT = "%H:%M"  DATE_FORMAT = "%d. %B %Y, {0}".format(TIME_FORMAT) DATE_FORMAT_THIS_YEAR = "%d. %B, {0}".format(TIME_FORMAT) DATE_FORMAT_THIS_WEEK = "%A, {0}".format(TIME_FORMAT) DATE_FORMAT_YESTERDAY = "Gestern, {0}".format(TIME_FORMAT) DATE_FORMAT_TODAY = "Heute, {0}".format(TIME_FORMAT)  DATE_FORMAT_SENTENCE = "am %d. %B %Y um {0} Uhr".format(TIME_FORMAT) DATE_FORMAT_THIS_YEAR_SENTENCE = "am %d. %B um {0} Uhr".format(TIME_FORMAT) DATE_FORMAT_THIS_WEEK_SENTENCE = "diesen %A um {0} Uhr".format(TIME_FORMAT) DATE_FORMAT_YESTERDAY_SENTENCE = "gestern um {0} Uhr".format(TIME_FORMAT) DATE_FORMAT_TODAY_SENTENCE = "heute um {0} Uhr".format(TIME_FORMAT) 

Algorithm to simplify 2D convex hull at the cost of extra area

Are there any algorithms related to the following problem that could be usefull for solving it?

I have a convex hull built on some point set. I would like to simplify it (reduce number of points) by still keeping its perimiter (or area) as small as possible. New simplified polygon should not intersect the original hull.

The basic idea I am trying to implement is to calculate for each point of a polygon perimeter added by removal of this point. And then remove the cheapest point (which removal adds minimum value to the perimiter).

So we keep iterating and removing points while added perimiter or area value is suitable and passes some creteria.

Here comes the problem:

When removing point p1 we introduce a new edge formed by previous point p0 and the next point p2. This new edge can be non-optimal or invalid (intersecting the original hull). So I would like to adjust points p0 and p2 along their edges to keep perimeter valid and small as possible.

How can I find these adjusted positions of p0 and p2 ?

Can a Fighter use his Extra Attack to draw a weapon as a free action?

The rules State: “You can also interact with one object or feature of the environment for free, during either your move or your action. For example, you could open a door during your move as you stride toward a foe, or you could draw your weapon as part of the same action you use to attack.”

Would the bolded parts apply to the extra attack as well as the triggering attack to allow a second weapon to be drawn?

Does a fighter’s Action Surge trigger Extra Attack?


Context

A player in my game will play a fighter with a greatsword. At 5th level he has Extra Attack and the option to use Action Surge. PHB p.72 states:

Action Surge. Starting at 2nd level, you can push yourself beyond your normal limits for a moment. On Your Turn, you can take one additional action on top of your regular action and a possible Bonus Action.

Once you use this feature, you must finish a short or Long Rest before you can use it again. Starting at 17th level, you can use it twice before a rest, but only once on the same turn.

Extra Attack. Beginning at 5th level, you can attack twice, instead of once, whenever you take the Attack action on Your Turn.

The number of attacks increases to three when you reach 11th level in this class and to four when you reach 20th level in this class.

Confusion

The questions and answers that I find on here deal with multi-classing or Two Weapon fighting specifically, which don’t really give a clear yes or no on my question.

The way I read these two features is that when a fighter takes an Attack action, he gets the Extra Attack. After using Action Surge he gets the opportunity to take another Attack action, and with that another Extra Attack. This results in four attacks with the greatsword in one turn, which sounds amazing but also rather powerful. Is this correct, or am I missing something?

What is a good way to add extra info to data-entries from a website front-end?

I want users to be able to dynamically add ‘columns’ from the front-end of the website. I understand that it is probably not best practice to actually add columns to a table from the front-end, so I was looking for a better way to handle this.

The use case:

I am making an app with a determination table. The user can fill out details of the animal/plant (for example leaf shape) and is supposed to end at the right species.

I want to make it future proof, so that if someone fills out all details and the species they have is not the one the table comes up with, the user can add both their species, and the detail that would tell both species apart.

For example: if the user found a daisy but the table comes up with dandelion, the user could add the daisy and add ‘petal colour’ as a distinquishing feature.

Users should then be able to fill out the petal colour for all plants that were already in the database.

My database at the moment:

I have one table where all details (like species name, leaf shape etc.) are stored in columns.

My webiste: I use angular 7 for the front-end, PHP on the server and a MySQL database, but general answers are also very welcome.

Using the_posts_pagination with offset adds extra empty page

I’m working on a quite complex query, it has a different post count on the first page and on paginated pages, to achieve that I’m using offset and this seem to mess up the_posts_pagination.

Here’s the code:

index.php

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>  //post content here... <?php endwhile; endif; ?>  <?php     the_posts_pagination( array(         'mid_size'  => 2,         'prev_text' => __( 'Prev', 'textdomain' ),         'next_text' => __( 'Next', 'textdomain' ),     )); ?> 

functions.php

function my_offset( $  query ) {     $  ppp = get_option( 'posts_per_page' );     $  first_page_ppp = 3;     $  paged = $  query->query_vars[ 'paged' ];      if( $  query->is_home() && $  query->is_main_query() ) {         if( !is_paged() ) {              $  query->set( 'posts_per_page', $  first_page_ppp );          } else {             $  paged_offset = $  first_page_ppp + ( ($  paged - 2) * $  ppp );             $  query->set( 'offset', $  paged_offset );          }     } } add_action( 'pre_get_posts', 'my_offset' );  function my_offset_pagination( $  found_posts, $  query ) {     $  ppp = get_option( 'posts_per_page' );     $  first_page_ppp = 3;      if( $  query->is_home() && $  query->is_main_query() ) {         if( !is_paged() ) {              return( $  found_posts );          } else {              return( $  found_posts - ($  first_page_ppp - $  ppp) );          }     }     return $  found_posts; } add_filter( 'found_posts', 'my_offset_pagination', 10, 2 ); 

The post per page is set to 5 in the reading settings, but the issue is there no matter what it’s set to.

Now using this code the the_posts_pagination will show at least one extra empty page in the numbered pagination links. However if I go to the second page then the numbered pagination will display the correct number of max pages.

Any help is much appreciated

Really weird bug (extra space required) in CSS style sheet

I have a weird bug in a CSS style sheet for my software project’s HTML-based documentation. I have left- and right-aligned header DIV styles declared as follows:

div.LHDR {     float: left;     text-align: left;     position: relative; }  div. RHDR { /* Weird: Remove the space and style class doesn't work! */     float: right;     text-align: center;     position: relative; } 

The single space after the “div.” for the second is what is confusing me. Take it away and any HTML content that uses it doesn’t work.

This is something I can live with but it disturbs my sense of perfection! Also, please bear in mind that this is my first post on Stack Overflow, so I may have made some errors in the submission format. A zipped-up folder with the CSS file and a sample HTM file for folks to try out can be downloaded here.

The issue occurs on Windows (7 and 10) and with IE, Edge and Opera, and also from within the compiled help (.chm) file. Still to try it out on a Mac. Also note that, for the equivalent ‘left’ aligned “div”, the space is not required.

Any comments on this are much appreciated!