Saturday, 27 November 2021

How to get sample rate, bit depth, and number of channels with Web Audio API?

I am wondering how I can get the following audio metadata after uploading a file and embedding within <audio> tag.

  • Sample rate
  • Bit depth
  • Number of channels

Is this possible with Web Audio API? Or do I need to parse the binary data of each audio file?



from How to get sample rate, bit depth, and number of channels with Web Audio API?

Leaflet highlight GeoJSON points within the other highlighted GeoJSON polygon

I would like to have all the points highlighted within the other highlighted GeoJSON polygon.

enter image description here

Next, I would like to have them displayed in the panel next to or at least in the console (for now).

The problem is, that code I provided doesn't work. I can't see these points anywhere.

     var ptsWithin = turf.within(placesLayer.toGeoJSON(), total.toGeoJSON());

     map.on('draw:created', function (e) {
     placesLayer.clearLayers();
     layer = e.layer;
     placesLayer.addLayer(layer);
     GetSelection(placesLayer);
     });

     function GetSelection(layer){

var shape2 = placesLayer.toGeoJSON()  //All facilities
var ptsWithin = turf.within(total, layer.toGeoJSON());

    alert('Found ' + ptsWithin.features.length + ' features');  
    alert("results "+JSON.stringify(ptsWithin));

};

which I've picked up from here:

Leaflet and Turf.js Points within poly

I also tried another approach:

 var eclplaces = total.toGeoJSON().geometry.coordinates
 placesLayer.eachLayer(function (layer) {
 if(turf.booleanContains(eclplaces, layer.toGeoJSON().geometry.coordinates)){
      selPts.push(layer.feature);
  }

but with no effect at all.

The same as this code:

Determine if a point reside inside a leaflet polygon

Is there any way to highlight and list the points, which are located inside the highlighted polygon?

My full code is here:

http://01.mlearnweb.online/

UPDATE:

I found another option here:

https://github.com/hayeswise/Leaflet.PointInPolygon

Determine if a point reside inside a leaflet polygon

but these functions are not suitable with my problem.



from Leaflet highlight GeoJSON points within the other highlighted GeoJSON polygon

Django - Full test suite failing when adding a TestCase, but full test suite passes when it is commented out. All TestCase pass when run individually

So this seems to be an issue talked about here and there on StackOverflow with no real solution. So I have a bunch of tests that all pass when run individual. They even pass when run as a full test suite, EXCEPT when I add in my TestCase ExploreFeedTest. Now ExploreFeedTest passes when run by itself and it actually doesn't fail when run in the full test suite as in running python manage.py test, it causes another test HomeTest to fail, which passes on it's own and passes when ExploreFeedTest is commented out from the init.py under the test folder. I hear this is an issue with Django not cleaning up data properly? All my TestCase classes are from django.test.TestCase, because apparently if you don't use that class Django doesn't teardown the data properly, so I don't really know how to solve this. I'm also running Django 3.2.9, which is supposedly the latest. Anyone have a solution for this?

ExploreFeedTest.py

from django.test import TestCase
from django.urls import reverse
from rest_framework import status    

class ExploreFeedTest(TestCase):

Folder setup

enter image description here

Here are some others having similar issue:

why would a django test fail only when the full test suite is run? Inconsistent Django test results depending upon how the test is called in Django 1.5.1 running on Python 2.7.4

here's a small snippet of the failing test I am getting

.............................FE.E.E.EFE.E.E.EFEFE.E.E.E.E.E.E.E.E.E.E..............................
======================================================================
ERROR: test_all_posts_contains_post_by_user_followees_and_follow_goal (cheers.test.PostTests.HomeTest.HomeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\envs\cheers\lib\site-packages\django\db\backends\utils.py", line 82, in _execute
    return self.cursor.execute(sql)
psycopg2.errors.ForeignKeyViolation: insert or update on table "cheers_post" violates foreign key constraint "cheers_post_join_goal_id_da1e6957_fk_cheers_joingoal_uuid"
DETAIL:  Key (join_goal_id)=(0947b806-f9f8-4e2c-98df-6072eaa61533) is not present in table "cheers_joingoal".

All the E I'm getting in the tests are essentially because of this. Keep in mind these all pass just fine when I comment out ExploreFeedTest and ExploreFeedTest passes successfully when ran alone. Also as you can see it's HomeTest failing.

Here's an example of one of the tests that's failing due to this error as well

class HomeTest(TestCase):
    @classmethod
    # Generates Test DB data to persist throughout all tests
    def setUpTestData(cls) -> None:
        cls.generate_count = 4
        cls.access_token = get_test_user_access_token()
        cls.num_posts = 0
        cls.user = create_test_user_in_DB()
        GoalCategory.objects.create(name='health', emoji_url='url')
        cls.goal = GoalFactory()
        cls.join_goal = JoinGoal.objects.create(joiner=cls.user, goal=cls.goal)

        # Posts by the current user
        for i in range(cls.generate_count):
            cls.num_posts += 1
            PostFactory()

        cls.followee = User.objects.create(uuid=uuid.uuid4(), username='Test')
        followee_join_goal = JoinGoal.objects.create(joiner=cls.followee, goal=cls.goal)
        FollowUser.objects.create(followee=cls.followee, follower=cls.user)
        # Posts by user the current user is following
        for i in range(cls.generate_count):
            cls.num_posts += 1
            Post.objects.create(creator=cls.followee, join_goal=followee_join_goal,
                                type=PostType.UPDATE, body='test')

        random_user = User.objects.create(uuid=uuid.uuid4(), username='Random')
        cls.followed_join_goal = JoinGoal.objects.create(joiner=random_user, goal=cls.goal)
        FollowGoal.objects.create(follower=cls.user, join_goal=cls.followed_join_goal)
        # Posts of goal current user is following
        for i in range(cls.generate_count):
            cls.num_posts += 1
            Post.objects.create(creator=random_user, join_goal=cls.followed_join_goal,
                                type=PostType.UPDATE, body='test')

        cls.count = int(cls.num_posts / 2) - 1
        cls.post_list = list(Post.objects.all().order_by('uuid'))
        cls.mid_idx, cls.mid_post = get_mid_idx_and_post_from_post_list(cls.post_list)

def test_all_posts_contains_post_by_user_followees_and_follow_goal(self):
    response = self.client.get(reverse('get_initial_home_feed',
                                       kwargs={'count': self.num_posts}),
                               **{'HTTP_AUTHORIZATION': f'bearer {self.access_token}'})
    self.assertEqual(response.status_code, status.HTTP_200_OK)
    self.assertEqual(len(response.data), self.num_posts)
    posts_by_user = list(Post.objects.filter(creator=self.user).values_list('uuid', flat=True))
    posts_by_followees = list(Post.objects.filter(creator=self.followee).values_list('uuid', flat=True))
    posts_of_followed_join_goal = list(
        Post.objects.filter(join_goal=self.followed_join_goal).values_list('uuid', flat=True))
    uuids_of_posts = [uuid.UUID(data['uuid']) for data in list(response.data)]
    self.assertTrue(all(uuid in uuids_of_posts for uuid in posts_by_user))
    self.assertTrue(all(uuid in uuids_of_posts for uuid in posts_by_followees))
    self.assertTrue(all(uuid in uuids_of_posts for uuid in posts_of_followed_join_goal))


from Django - Full test suite failing when adding a TestCase, but full test suite passes when it is commented out. All TestCase pass when run individually